我正在尝试在WPF中实现一个可展开的控件,其中包含一些嵌套的控件。其中之一是Wrap Panel,我希望它能够随着用户更改窗口大小而自动换行。
如果我将WrapPanel控件的Grid Control父控件取出并放到自己的应用程序中,这样就可以正常工作,但在这种格式下却不能正常工作。由于我没有为此Grid设置最小宽度,所以这让我感到惊讶。有什么想法吗?谢谢。
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" FontFamily="Calibri" FontSize="8">
<StackPanel Orientation="Vertical">
<Expander Margin="3" Padding="3">
<Expander.Header>
<StackPanel Orientation="Horizontal" MinWidth="150" Width="Auto" MinHeight="25">
<Label MinWidth="50">Label 1</Label>
<CheckBox VerticalAlignment="Center"></CheckBox>
<Border></Border>
<Label>Label 2</Label>
</StackPanel>
</Expander.Header>
<Expander.Content>
<StackPanel Orientation="Horizontal" >
<Label MinWidth="150">Add Image</Label>
<Grid Name="Grid1" ShowGridLines="True" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Name="Title1" MinHeight="25"></RowDefinition>
<RowDefinition Name="Number1" MinHeight="25"></RowDefinition>
<RowDefinition Name="PlaneA" MinHeight="25"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Name="Plane1" MinWidth="25" Width="Auto"></ColumnDefinition>
<ColumnDefinition Name="PlaneCheckBox" MinWidth="25" Width="Auto"></ColumnDefinition>
<ColumnDefinition Name="Border1" MinWidth="25" Width="Auto"></ColumnDefinition>
<ColumnDefinition Name="List1" Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<WrapPanel Grid.Row="2" Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
<Label Grid.Column="1">No. 1</Label>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
<Label Grid.Column="1">No. 1</Label>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
<ColumnDefinition MinWidth="25"></ColumnDefinition>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" VerticalAlignment="Center"></CheckBox>
<Label Grid.Column="1">No. 1</Label>
</Grid>
</WrapPanel>
</Grid>
</StackPanel>
</Expander.Content>
</Expander>
</StackPanel>