注意:我们可以修改GridSplitter左右两边的单元格的 MinWidth和MaxWidth属性值,从而影响到GridSplitter能够左右移动的范围
注意:VerticalAlignment="Stretch" 使用的是Stretch
Code
<UserControl x:Class="MySplitControl.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sp="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" ShowGridLines="True" Background="White" Width="400" Height="300">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="350" MinWidth="250"/>
<ColumnDefinition Width="25" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle Fill="Red" Grid.Column="0" Grid.Row="0"></Rectangle>
<Rectangle Fill="Blue" Grid.Column="1" Grid.Row="0"></Rectangle>
<Rectangle Fill="Aqua" Grid.Column="2" Grid.Row="0"></Rectangle>
<sp:GridSplitter x:Name="grsplSplitterColumn" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Yellow" Width="6"></sp:GridSplitter>
</Grid>
</UserControl>