我不能让我的WPF布局工作.我希望ListBox通过锚定到窗口底部来垂直拉伸.它当前只是StackPanel("添加"和"删除"按钮)中控件高度的大小,并调整大小以容纳添加的项目.在WinForms中我会设置ListView.Anchor,Top|Left|Bottom|Right但我不应该活在过去.我已经尝试了很多东西,比如把它放进去DockPanel,把所有东西都装进去Canvas等等,但似乎没有任何影响.

这是我的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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10355 次 |
| 最近记录: |