.NET GridSplitter调整一列的大小 [英] .NET GridSplitter to resize one column

查看:108
本文介绍了.NET GridSplitter调整一列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很具体,没有发现任何相关的地方.因此,关于SO的我的生活中的第一个问题,我们走了.我是WPF和XAML全局的新手,所以如果您有任何改进我的代码的意见,请不要犹豫.

My question is quite specific and did not find anything related anywhere. So first question of my life on SO, here we go. I new to WPF and XAML globaly so do not hesitate if you have any remarks to improve my code.

我想实现什么?我有一个由4个菜单包围的工作区.此菜单的可见性取决于顶部的切换按钮,但我会删除所有内容,从而使代码更清晰.但是我希望菜单的行为类似于弹出菜单(我没有使用弹出窗口来真正控制tjose菜单的特定容器内的大小和位置).左侧有2个菜单,右侧有2个菜单.在每一侧,两个菜单不能同时打开.同样,我将清除所有这些内容.我希望菜单可以调整大小.但是我左边的两个菜单的大小不一样,应该分别调整大小.

What I try to achieve ? I have a workspace surrounded by 4 menus. The visibility of this menu are conditioned by toggle buttons on top but I erase all that so my code is clearer. But I want menu that behave like pop up (I did not use pop up to really control the size and position, inside a certain container, of tjose menus). There are 2 menus on the left and two menus on the right. On each side, the two menu can not be opened at the same time. Same thing, I erase all this to be clear. I want my menus to be resizable. But my two menu on the left does not have the same size and should be resize individually.

<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0" Background="Aqua" Name="LeftMenu">
        <Grid Name="LeftMenu1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="200" MaxWidth="500" Width="300"/>
                <ColumnDefinition Width="5"/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0"  Name="MenuContent1"/>
            <GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndCurrent" HorizontalAlignment="Stretch"/>
        </Grid>
    </Grid>
    <Grid Grid.Column="1" Name="Workspace"/>
    <Grid Grid.Column="2" Background="Aqua" Name="RightMenu">
        <Grid Name="RightMenu1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="5"/> 
                <ColumnDefinition MinWidth="200" MaxWidth="500" Width="300"/>
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="0" ResizeBehavior="CurrentAndNext" HorizontalAlignment="Stretch"/> 
            <Grid Grid.Column="1" Name="MenuContent2"/>
        </Grid>
    </Grid>

</Grid>

*我只显示了每侧的一个菜单,因为我删除了可见性条件,但是第二个菜单是相同的,只是宽度不同.

*I only diplayed one menu on each side because I erased the visibility condition, but the second menus are the same, exept for the width.

我怎么了?如您所见,我使用GridSplitter调整了组成每个菜单的一列网格的大小.尽管我的期望行为完全在左侧,但在右侧却不起作用.当我使用Gridsplitter时,将调整gridsplitter列(当前")的大小,而不是菜单列的大小.我使用了"CurrentandNext"值,因为它看起来合乎逻辑,但显然还不够.如果我用maxWidth和minWidth固定了GridSplitter的宽度,则不需要任何操作,GridSplitter不会移动.

What is my problem ? As you can see I used GridSplitter to resize the one column grid that compose each menu. While I totally get my wanted behavior on the left, it does not work on the right. When I use the Gridsplitter, the gridsplitter column ("current") is resized and not the menu column. I used the "CurrentandNext" value as it seemed logical but it is apparently not sufficient. If I fixed the GridSplitter width with maxWidth and minWidth, nothing is resied, the GridSplitter does not move.

我希望我足够清楚,欢迎任何帮助!

I hope that I am clear enough and will welcome any help !

推荐答案

我需要有两个面板",它们不能同时打开,但是大小不同...

I need to have two "panels", not opened at the same time, but with a different size...

我确实为问题

I do made a solution for the question WPF How to build docked resizable expanders and grid using XAML only? and and it works for your question too.

调整列大小时,您犯了一个错误.

You made a bit of a mistake when sizing the columns.

<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0" Background="Aqua" Name="LeftMenu">
        <Grid Name="LeftMenu1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0"  Name="MenuContent1" MinWidth="200" MaxWidth="500" Width="300"/>
            <GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndCurrent" HorizontalAlignment="Stretch" Width="5"/>
        </Grid>
    </Grid>
    <Grid Grid.Column="1" Name="Workspace"/>
    <Grid Grid.Column="2" Background="Aqua" Name="RightMenu">
        <Grid Name="RightMenu1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="0" ResizeBehavior="CurrentAndNext" HorizontalAlignment="Stretch" Width="5"/>
            <Grid Grid.Column="1" Name="MenuContent2" MinWidth="200" MaxWidth="500" Width="300"/>
        </Grid>
    </Grid>

</Grid>

这篇关于.NET GridSplitter调整一列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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