XAML 拉伸列表视图以匹配扩展器宽度

wixjitnu  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(116)

如何将列表视图的宽度设置为与它所在的扩展器的宽度相同?

<Expander x:Name="expander"
              IsExpanded="False" 
              ExpandDirection="Down" 
              Header="Main" 
              HorizontalAlignment="Stretch" 
              Grid.Column="1"
              Grid.Row="1">
            <Expander.Content>
                <ListView x:Name="listView"
                          SelectionMode="None"
                          IsItemClickEnabled="True"
                          HorizontalAlignment="Stretch"
                          ItemClick="ListItemClicked"
                          ItemTemplate="{StaticResource ListViewTemplate}"/>
            </Expander.Content>
</Expander>
vuv7lop3

vuv7lop31#

像这样将HorizontalContentAligment="Stretch"加到Expander上。

<Expander
    x:Name="expander"
    Grid.Row="1"
    Grid.Column="1"
    HorizontalAlignment="Stretch"

    HorizontalContentAlignment="Stretch"

    ExpandDirection="Down"
    Header="Main"
    IsExpanded="False">
    <Expander.Content>
        <ListView
            x:Name="listView"
            HorizontalAlignment="Stretch"
            IsItemClickEnabled="True"
            SelectionMode="None" >
            <ListViewItem Content="Test"/>
            </ListView>
    </Expander.Content>
</Expander>

相关问题