我在设置网格中的列宽时遇到了一些麻烦。我想实现最左边的列在启动时(应用程序)200 像素宽度,但仍然可以调整大小。这是我的代码:
<Grid x:Name="MainGrid" Width="1000" Height="600">
<Grid x:Name="MainGrid" HorizontalAlignment="Left" Height="600" VerticalAlignment="Top" Width="1000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="500"/>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" MinWidth="200"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Visible">
<TextBox Grid.Column="0" x:Name="textBox" Text="Doei, Hoi" MinWidth="200"/>
</ScrollViewer>
<GridSplitter Grid.Column="1" x:Name="gridSplitter" HorizontalAlignment="Center" Height="auto" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="5" ResizeDirection="Columns" Background="#FF464444"/>
<ScrollViewer Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Visible">
<TextBox Grid.Column="2" x:Name="textbox1" Text="Hoi, Doei" MinWidth="200"/>
</ScrollViewer>
</Grid>
</Grid>
我的问题是我不知道如何设置列的起始宽度。也许我使用了错误的搜索词,但我找不到任何可以解决我问题的东西
当前最新代码:
<Window x:Class="ServerWPF.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:ServerWPF"
mc:Ignorable="d"
Title="Chat Server" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight">
<Grid x:Name="MainLeft" HorizontalAlignment="Left" Height="600" VerticalAlignment="Top" Width="1000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="500"/>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" MinWidth="200"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Visible">
<TextBox Grid.Column="0" x:Name="textBox" Text="Doei, Hoi" MinWidth="200"/>
</ScrollViewer>
<GridSplitter Grid.Column="1" x:Name="gridSplitter" HorizontalAlignment="Center" Height="auto" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="5" ResizeDirection="Columns" Background="#FF464444"/>
<ScrollViewer Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Visible">
<TextBox Grid.Column="2" x:Name="textbox1" Text="Hoi, Doei" MinWidth="200"/>
</ScrollViewer>
</Grid>
</Window>