我无法让我的WPF布局工作。我希望ListBox通过锚定到窗口的底部来垂直拉伸。它目前只是调整到StackPanel
(添加和删除按钮)中控件的高度,并调整大小以适应添加的项目。在WinForms中,我只是将ListView.Anchor
设置为Top|Left|Bottom|Right
,但我不应该生活在过去。我已经尝试了一些东西,比如将它放在DockPanel
中,将所有内容都包装在Canvas
等中,但似乎没有任何影响。获取WPF控件垂直拉伸
这是我的XAML:
<Window x:Class="FileDropAdmin.ViewsTestListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:shared="http://schemas.markpad.net/winfx/xaml/shared"
Title="ViewsTestListView" Height="300" Width="416">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top" Text="Things:" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<ListBox x:Name="Things" DisplayMemberPath="ThingName" SelectedItem="CurrentThing" Grid.Column="0"/>
<StackPanel Margin="5 0 0 0" VerticalAlignment="Top" Grid.Column="1">
<Button x:Name="AddThing" Content="Add" Margin="0 0 0 0" VerticalAlignment="Top"/>
<Button x:Name="RemoveThing" Content="Remove" Margin="0 5 0 0" VerticalAlignment="Top"/>
</StackPanel>
</Grid>
</Grid>
</Window>
完美!谢谢:-D – 2012-03-06 06:19:17