以下代码用于表示可调整大小的视口("黑色边框"),我可以使用横向GridSplitters调整视口矩形的大小。
我想要做的是,通过拖动中间的GridSplitter来移动整个边框,即调整第一列和最后一列的宽度,同时保持其他列的宽度。
这可能吗?我不介意一些代码隐藏,但我想相信它可能没有必要吗?
<Window x:Class="GridSplitterViewport.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GridSplitterViewport"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60*"/>
<RowDefinition Height="259*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="LightGray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="ViewPort" Grid.Column="1" Grid.ColumnSpan="3" Background="#3000" BorderBrush="Black" BorderThickness="0 4"/>
<GridSplitter x:Name="ResizeLeft" Grid.Column="1" Background="Black" HorizontalAlignment="Stretch"/>
<GridSplitter x:Name="Move" ResizeDirection="Columns" Grid.Column="2" Background="Transparent" HorizontalAlignment="Stretch"/>
<GridSplitter x:Name="ResizeRight" Grid.Column="3" Background="Black" HorizontalAlignment="Stretch"/>
</Grid>
</Grid>
答案 0 :(得分:1)
这个怎么样:
<Grid Grid.Row="0" Background="LightGray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="ViewPort" Grid.Column="1" Background="#3000" BorderBrush="Black" BorderThickness="0 4"/>
<GridSplitter x:Name="ResizeLeft" Grid.Column="0" Background="Black" HorizontalAlignment="Right" Width="6" Margin="-6,0,0,0"/>
<GridSplitter x:Name="Move" ResizeDirection="Columns" Grid.Column="1" Background="Transparent" HorizontalAlignment="Stretch"/>
<GridSplitter x:Name="ResizeRight" Grid.Column="2" Background="Black" HorizontalAlignment="Left" Width="6"/>
</Grid>