WPF窗口与3网格

本文关键字:网格 窗口 WPF | 更新日期: 2023-09-27 18:01:20

我想在主窗口中构建application,我有3个Grid和2个GridSplitter之间:

<Window x:Class="PlayTube.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="625">
    <Grid Background="#FFD86F6F">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Background="#FFFFFF89" MaxWidth="200">
        </Grid>
        <GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Column="1" ResizeBehavior="PreviousAndNext"
                  Width="5" Background="#FFBCBCBC" />
        <Grid Background="#FF05BECB" Grid.Column="2">
        </Grid>
        <GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Column="3" ResizeBehavior="PreviousAndNext"
                  Width="5" Background="#FFBCBCBC"/>
        <Grid Background="#FF4E04A7" Grid.Column="4">
        </Grid>
    </Grid>
</Window>

我想让前两个网格的最大宽度为200px。当我尝试用GridSplitter重新调整网格大小时,网格保持最大200,但我可以看到主网格的颜色。

你知道是什么问题吗?

WPF窗口与3网格

尝试将MaxWidth属性移动到ColumnDefinition而不是网格。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="625">
    <Grid Background="#FFD86F6F">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" MaxWidth="200"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid Background="#FFFFFF89" >
        </Grid>
        <GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Column="1" ResizeBehavior="PreviousAndNext"
                  Width="5" Background="#FFBCBCBC" />
        <Grid Background="#FF05BECB" Grid.Column="2">
        </Grid>
        <GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Column="3" ResizeBehavior="PreviousAndNext"
                  Width="5" Background="#FFBCBCBC"/>
        <Grid Background="#FF4E04A7" Grid.Column="4">
        </Grid>
    </Grid>
</Window>