如何在ListPanel上停靠ListView?

时间:2009-11-23 09:44:25

标签: wpf listview stackpanel dock

<StackPanel Grid.Row="0" Height="Auto" Width="Auto">
    <Label Name="Label1" BorderThickness="2,2,2,2" BorderBrush="Gray" HorizontalContentAlignment="Center" Width="Auto" Height="28">Window1</Label>               
    <ListView BorderThickness="2,0,2,0" BorderBrush="Gray"Height="Auto" Width="Auto" />                                   
</StackPanel>

在上面的XAML中,我想将ListView停靠在StackPanel上。我希望ListViewStackPanel之后占用Label的整个客户区。

我做错了什么?

2 个答案:

答案 0 :(得分:3)

为什么不使用DockPanel

<DockPanel Grid.Row="0" Height="Auto" Width="Auto">
     <Label DockPanel.Dock="Left" Name="Label1" BorderThickness="2,2,2,2" BorderBrush="Gray"  HorizontalContentAlignment="Center" Width="Auto" Height="28">Window1</Label>               
     <ListView BorderThickness="2,0,2,0" BorderBrush="Gray" Height="Auto" Width="Auto" />
</DockPanel>

答案 1 :(得分:0)

长话短说,StackPanel并不意味着伸展它的孩子,它会在它们到来时叠加它们。你想要一个DockPanel

这是discussed before