How to get WPF GridSplitter to resize my grid?

WPF GridSplitter makes my grid wider than my window!

I have a WPF Grid with a GridSplitter. If I resized my columns, then I can make the grid wider than my window and cannot be viewed.

It starts as follows:

WPF Grid http://img201.imageshack.us/img201/9505/onehg6.jpg

But after expanding the left column, I can no longer see the right column (green):

WPF GridSplitter http://img201.imageshack.us/img201/1804/twomy6.jpg

What am I doing wrong? How to make GridSplitter resize my grid?


Update:

I'm still struggling with this. Now I have tried nested grids in meshes. It did not help. Here are my XAML ColumnDefinitions, RowDefinitions and GridSplitters ...

<Window ... >
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" MinWidth="150" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" MinWidth="400" />
        </Grid.ColumnDefinitions>
        <GridSplitter 
            ResizeDirection="Columns"
            ResizeBehavior="BasedOnAlignment"
            Grid.Column="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Stretch"
            Width="2"
            Margin="0,5,0,5"
            Panel.ZIndex="1"/>
        <Grid Grid.Column="0">
            ...
        </Grid>
        <Grid Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" MinWidth="150" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" MinWidth="200" />
            </Grid.ColumnDefinitions>
            <GridSplitter 
                ResizeDirection="Columns"
                ResizeBehavior="PreviousAndNext"
                Grid.Column="1"
                HorizontalAlignment="Center"
                VerticalAlignment="Stretch"
                Width="2"
                Margin="0,5,0,5"
                Panel.ZIndex="1"/>
            <Grid Grid.Column="0">
                ...
            </Grid>
            <Grid Grid.Column="2">
                ...
            </Grid>
        </Grid>
    </Grid>
</Window>

Update:

, WebBrowser. . :

WPF GridSplitter WebBrowser?

+5
4

, MinWidths , , , :

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="150" Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition MinWidth="400" Width="*"/>
        </Grid.ColumnDefinitions>
        <GridSplitter
            Width="2"
            Grid.Column="1"
            HorizontalAlignment="Center"
            Margin="0,5,0,5"
            Panel.ZIndex="1"
            VerticalAlignment="Stretch"
            ResizeBehavior="BasedOnAlignment"
            ResizeDirection="Columns"/>
        <Grid Grid.Column="0">
            <Border Background="Red" Margin="5"/>
        </Grid>
        <Grid Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="150" Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition MinWidth="200" Width="*"/>
            </Grid.ColumnDefinitions>
            <GridSplitter
                Width="2"
                Grid.Column="1"
                HorizontalAlignment="Center"
                Margin="0,5,0,5"
                Panel.ZIndex="1"
                VerticalAlignment="Stretch"
                ResizeBehavior="PreviousAndNext"
                ResizeDirection="Columns"/>
            <Grid Grid.Column="0">
                <Border Background="Green" Margin="5"/>
            </Grid>
            <Grid Grid.Column="2">
                <Border Background="Blue" Margin="5"/>
            </Grid>
        </Grid>
    </Grid>
</Window>

, , MinWidth 400, .

, , ...

+3

Width . , , , , . .

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="2*" MinWidth="100" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" MinWidth="50" />
        <ColumnDefinition Width="2*" MinWidth="100" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="3*" MinWidth="150" />
    </Grid.ColumnDefinitions>
    <GridSplitter 
        ResizeDirection="Columns"
        Grid.Column="1"
        Grid.RowSpan="8"
        HorizontalAlignment="Center"
        VerticalAlignment="Stretch"
        Width="2"
        Margin="0,5,0,5"
        Panel.ZIndex="1"/>
    ...
</Grid>
+6

- , , ..

<Grid >
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="20*" MinWidth="50" MaxWidth="500" />
    <ColumnDefinition Width="Auto"/> <!-- Remove such columns /-->
    <ColumnDefinition Width="100*" MinWidth="850"/>
    <ColumnDefinition Width="30*" MinWidth="50" MaxWidth="800" />
</Grid.ColumnDefinitions>
...
<GridSplitter HorizontalAlignment="Right" Width="3"/>
...
<GridSplitter Grid.Column="3" HorizontalAlignment="Left" Width="3" />
<!-- Assign Grid.Column to 2 if you remove the auto width column /-->
...
</Grid>

.

+3

DragDelta - :

private void VerticalGridSplitter_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
    if (GridName.ColumnDefinitions[2].Width.Value < 400)
    {
        GridName.ColumnDefinitions[2].Width = new GridLength(400);
    }
}

MinWidth * ColumnDefinition . , ColumnDefinition MinWidth . , .

+2

All Articles