Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何将ListView高度设置为XAML中连续行的高度_Wpf_Xaml_Listview_Binding - Fatal编程技术网

Wpf 如何将ListView高度设置为XAML中连续行的高度

Wpf 如何将ListView高度设置为XAML中连续行的高度,wpf,xaml,listview,binding,Wpf,Xaml,Listview,Binding,我搞不懂告诉ListView它的高度是包含ListView的行的高度的语法,也就是ListView的父行的高度。 这是用户控件中的xaml。我把我认为有用的东西放进去了,但没有。我把它放在那里了,这样你就能看到我在尝试什么 <ListView Grid.Row="1" Height="{Binding Path=Height,RelativeSource={RelativeSource AncestorType=Grid.Row}}" ItemsSource="{Binding Fold

我搞不懂告诉ListView它的高度是包含ListView的行的高度的语法,也就是ListView的父行的高度。 这是用户控件中的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"
/>


谢谢,

只需将行定义高度设置为自动,这是我的xaml:

<Grid Background="DimGray">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <StackPanel Background="CornflowerBlue"/>
        <ListView Grid.Row="1" 
                  x:Name="ListView"
                  ItemsSource="{Binding Items}"
                  SelectionMode="Single"
                  SelectedIndex="1"
                  VerticalAlignment="Stretch"
                  HorizontalAlignment="Stretch"
                  Margin="3"
                  ScrollViewer.VerticalScrollBarVisibility="Visible"
                  ScrollViewer.CanContentScroll="True"/>

        <StackPanel Grid.Row="2" Background="CornflowerBlue"/>
    </Grid>

以及输出:

如果使用星号表示法,则该行将采用您给出的星号值的可用高度,在本例中为1*,与*******相同。 如果我修改为使用星号值:

<Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>

输出:


希望这有帮助

无需重复。除此之外,
AncestorType=Grid.Row
没有任何意义(因为Grid.Row不是类型),只需删除高度指定即可。默认情况下,栅格将自动调整其子元素的大小。阅读有关Grid类的在线文档,尤其是其RowDefinitions和ColumnDefinitions属性。感谢您的回复,Will。您的图像显示了我在添加height属性之前拥有的内容。行定义包括设置为自动的第0行和设置为*的第1行。我命名了网格,然后将Height属性设置为元素的实际高度。问题是listView位于可见区域下方。感谢您的回复。我在最初的问题中没有输入足够的代码。如果我有,每个人都会看到问题不在于我原来的ListView(它没有设置height属性),而在于HeaderedContentControl,它是行中的第一项。我只是把行设置错了,这就产生了问题。当我的清单不合适的时候,我一直在看它,而不是更大的图景。当我删除标题内容控件以减少混乱时,我的列表视图自行修复。我将此标记为答案,因为它对将来的人更有用。