伸展空WPF的ListView采取的剩余空间 [英] Stretch empty WPF ListView to take the remaining space

查看:243
本文介绍了伸展空WPF的ListView采取的剩余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有问题,像StackPanel的动态布局控件内一个ListView。

I always have problems with a ListView inside a dynamic layout control like a Stackpanel.

现在我有一个StackPanel中作为根控件的窗口。该StackPanel中完美口延伸,并采取完整的窗口。在StackPanel中里面是像文本框和按钮都排列良好。

Right now I have a Window with a Stackpanel as Root-Control. The Stackpanel streches perfectly and takes the complete window. Inside the StackPanel are some other controls like textboxes and button all aligned fine.

最后一个对象是一个ListView。我想在ListView采取从StackPanel中的剩余空间,但事实并非如此。即使有 VerticalAlignment =拉伸我只得到了列标题。当项目被添加到它的ListView控件只生长。所以,我必须手动设置ListView的高度。

The last Object is a ListView. I want the ListView to take the remaining space from the StackPanel but it does not. Even with VerticalAlignment="Stretch" I only get the column headers. The ListView only grows when items are added to it. So I have to set the ListView height manually.

如何让ListView的填写StackPanel中的剩余空间,即使它是空的?

How can I make the ListView fill the remaining space in a StackPanel even when it is empty?

推荐答案

此无关的ListView控件。这是StackPanel中的过失。在StackPanel的子项中的总是仅消耗他们需要(在StackPanel中的方位方向)的空间。这就是StackPanel的是如何设计的。使用DockPanel中相反,那里你可以让最后一个项目填补了所有剩下的使用 LastChildFill =真正的真实是默认的,所以无需显式指定它)。

This has nothing to do with the ListView. It is the StackPanel's "fault". In a StackPanel the child items always consume only the space they need (in the direction of the orientation of the StackPanel). That's how the StackPanel is designed. Use a DockPanel instead, there you can make the last item fill up all the space that is left over using LastChildFill="true" (true is default, so no need to explicity specify it).

<DockPanel Background="Green">
    <Button DockPanel.Dock="Top">Text</Button>
    <ListView DockPanel.Dock="Top">
        <ListView.View>
            <GridView>
                <GridViewColumn/>
            </GridView>
        </ListView.View>
    </ListView>     
</DockPanel>

这篇关于伸展空WPF的ListView采取的剩余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆