0

我想application在主窗口中构建它,它们之间有 3Grid和 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,但我可以看到主网格颜色。

知道有什么问题吗?

4

1 回答 1

2

Try moving the MaxWidth property to the ColumnDefinition instead of the grid.

<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>
于 2013-02-27T16:58:16.480 回答