带有3个网格的WPF窗口

时间:2013-02-27 16:53:47

标签: c# .net wpf

我想构建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>

我希望前两个网格最大宽度为200像素。当我尝试使用GridSplitter重新调整大小时,网格最大可保持200但我可以看到主网格颜色。

知道这是什么问题吗?

1 个答案:

答案 0 :(得分:2)

尝试将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>