这是XAML:
<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Background="Red"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5"></GridSplitter>
<Border Background="Green" Grid.Column="1"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5" Grid.Column="1"></GridSplitter>
<Border Background="Blue" Grid.Column="2"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5" Grid.Column="2"></GridSplitter>
</Grid>
</Window>
我发现我无法通过最后GridSplitter
来调整最后一列的宽度。
此外,所有其他GridSplitter
都运行良好。
为什么是这个?我该如何解决呢?
谢谢。
答案 0 :(得分:1)
尝试将其添加到网格的RowDefinition中,如下所示(添加带有*作为宽度的额外列以占用剩余空间)。
<ColumnDefinition Width="*"></ColumnDefinition>
这就是最终Xaml的外观(仅内容部分)
<Grid HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Background="Red"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5"></GridSplitter>
<Border Background="Green" Grid.Column="1"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5" Grid.Column="1"></GridSplitter>
<Border Background="Blue" Grid.Column="2"></Border>
<GridSplitter HorizontalContentAlignment="Stretch" Width="5" Grid.Column="2"></GridSplitter>
</Grid>
尝试并让我们知道这是您要寻找的还是需要其他帮助。