我可以使用 GridSplitter 拖动列而不调整它的大小吗?
Can I use a GridSplitter to drag a column without resizing it?
以下代码旨在表示可调整大小的视口("black border"),我可以使用横向 GridSplitter 来调整视口矩形的大小。
我想做的是,通过拖动中间的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>
这个怎么样:
<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>
以下代码旨在表示可调整大小的视口("black border"),我可以使用横向 GridSplitter 来调整视口矩形的大小。
我想做的是,通过拖动中间的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>
这个怎么样:
<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>