我如何保持WPF GridSplitter更改我的网格大小? [英] How do I keep the WPF GridSplitter from changing the size of my Grid?

查看:478
本文介绍了我如何保持WPF GridSplitter更改我的网格大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF GridSplitter让我的网格比我的窗口更宽!

WPF GridSplitter makes my Grid wider than my Window!

我有一个WPF网格与GridSplitter。如果我调整我的专栏的话,我可以让我的网格比我的窗口和非可视宽。

I've got a WPF Grid with a GridSplitter. If I resize my columns, then I can make my grid wider than my window and non-viewable.

它开始是这样的:

但扩大左侧立柱后,我再也不能看到右边一列(绿色):

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

我是什么做错了吗?我如何保持GridSplitter更改我的网格大小?

What am I doing wrong? How do I keep the GridSplitter from changing the size of my Grid?


更新:

我仍挣扎与此有关。现在,我已经试过网格内的嵌套网格。这并没有帮助。这是我的XAML ColumnDefinitions,RowDefinitions和GridSplitters ...

I'm still struggling with this. I've now tried nesting grids within grids. That didn't help. Here's 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>



更新:

我认为这个问题是与WebBrowser控件。看到了新的问题:

I think the problem is with the WebBrowser control. See new question:

<一个href="http://stackoverflow.com/questions/375841/wpf-gridsplitter-doesnt-work-with-webbrowser-control">WPF GridSplitter不与WebBrowser控件的工作?

推荐答案

如果您调整窗口的大小,以便它的宽度小于你列的总和MinWidths,你会看到列切断,但除此之外,我可以' T上重放您的问题:

If your Window is resized so its Width is less than the sum of your columns' MinWidths, you'll see the columns cut off, but otherwise I can't reproduce your problem:

<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>

扩大红柱,只会扩大,直至右列达到400它了minWidth,它不会启动它关闭的页面。

Expanding the red column, it will only expand until the right column reaches its MinWidth of 400, it won't boot it off the page.

这是可能你设置的窗口或最外层电网的其他属性,将导致此行为......

It's possible you're setting other properties of the Window or the outermost Grid that would cause this behavior...

这篇关于我如何保持WPF GridSplitter更改我的网格大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆