views:

20

answers:

0

I have the XAML shown below (for example). If you drag the grid splitter as far as it goes to the left, and keep dragging the mouse, the right-hand column will grow in size outside the bounds of the window - obviously not what I want.

The problem is that I can't set a hard MaxWidth on the right-hand column because the user can resize the window, thus increasing the available space for that column. So far I think I need to bind the MaxWidth of the right-hand column to something like the window's client area minus the MinWidth of the left plus the width of the splitter column. But I'd like to avoid that if possible. Thoughts?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Width="450"
        Height="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" MinWidth="100" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="200" MinWidth="200" />
        </Grid.ColumnDefinitions>

        <Grid Grid.Column="0">
            <Button>Monkey</Button>
        </Grid>

        <GridSplitter Grid.Column="1" Width="7" ResizeBehavior="PreviousAndNext" />

        <Grid Grid.Column="2" Margin="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <GroupBox Grid.Row="0" Header="Spaghetti" Margin="0, 0, 0, 5">
                <ComboBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch">Noodles</ComboBox>
            </GroupBox>

            <Expander Grid.Row="1" Header="Batman" IsExpanded="True" Margin="0, 0, 0, 5">
                <Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch">Batman!</Button>
            </Expander>
        </Grid>
    </Grid>
</Window>