【发布时间】:2017-11-27 05:16:31
【问题描述】:
我无法弄清楚告诉ListView它的高度是包含ListView的行的高度的语法,即ListView的Parent。 这是用户控件中的 xaml。我已经放了我认为可行的东西,但没有。我把它放在那里,所以你会看到我在尝试什么。
<ListView Grid.Row="1"
Height="{Binding Path=Height,RelativeSource={RelativeSource AncestorType=Grid.Row}}"
ItemsSource="{Binding Folders}"
ItemTemplate="{StaticResource FolderListTemplate}"
SelectionMode="Single"
SelectedIndex="1"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="3"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.CanContentScroll="True"
/>
谢谢,
【问题讨论】:
-
除了
AncestorType=Grid.Row没有意义(因为 Grid.Row 不是类型),只需删除高度分配。默认情况下,Grid 将自动调整其子元素的大小。阅读有关 Grid 类的在线文档,尤其是它的 RowDefinitions 和 ColumnDefinitions 属性。 -
感谢您的回复,威尔。您的图像显示了我在添加 height 属性之前所拥有的内容。行定义包括设置为 Auto 的第 0 行和设置为 * 的第 1 行。我命名了网格,然后将 Height 属性设置为元素的 ActualHeight。问题在于 listView 低于可见区域。