我想要的是:
我有什么:
当我调整表单大小时,所有3列都会改变它们的大小,而不仅仅是中间的列
<ToolBarTray DockPanel.Dock="Top" IsLocked="True" Background="Pink">
<ToolBar Height="26" Background="Beige">
</ToolBar>
</ToolBarTray>
<StatusBar DockPanel.Dock="Bottom" Height="23" Background="Orange"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="50"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width ="*" MinWidth="100"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" MinWidth="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GridSplitter Grid.Column="1" Width="5" ShowsPreview="True" Background="Red" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
<GridSplitter Grid.Column="3" Width="5" ShowsPreview="True" Background="Red" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
</Grid>
到目前为止感谢:)
答案 0 :(得分:1)
设置左列和右列的宽度(默认大小),它应该是工作
<Grid>
<StatusBar Height="23" Background="Orange" DockPanel.Dock="Bottom"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="50" Width="200"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="100" Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="50" Width="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GridSplitter
Width="5"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Background="Red"
ShowsPreview="True"/>
<GridSplitter
Width="5"
Grid.Column="3"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Background="Red"
ShowsPreview="True"/>
</Grid>
</Grid>
修改强>
这是针对第一个网格最大化问题的修复
<Grid x:Name="Root">
<Grid.Resources>
<local:MaxWidthConverter x:Key="MaxWidthConverter" />
</Grid.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="50"
Width="200"
MaxWidth="{Binding ElementName=Root, Path=ActualWidth, Mode=OneWay, Converter={StaticResource MaxWidthConverter}, ConverterParameter=260}" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200"
Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="50"
Width="200" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridSplitter Width="5"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Background="Red"
ShowsPreview="True" />
<GridSplitter Width="5"
Grid.Column="3"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Background="Red"
ShowsPreview="True" />
</Grid>
</Grid>
简单转换器计算第一列的最大宽度(260 = 200 minwidth + 50 minwidth + 5 splitter width + 5 splitter width
public class MaxWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double minWidth;
if (value is double && parameter is string && double.TryParse((string)parameter, NumberStyles.Any, CultureInfo.InvariantCulture, out minWidth)) {
var maxWidth = (double)value - minWidth;
return maxWidth < 0 ? 0 : maxWidth;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}