自动调整网格的列 [英] Auto sizing columns of grid

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

问题描述

我有一个网格和两列..在第二列中放置一个扩展器...基于扩展或折叠它,第一列的宽度应该有所不同.更具体地说,当扩展器处于折叠状态时,第一个网格中的内容应占据整个窗口,并且在扩展时,应调整第一列的宽度以为扩展器中的内容留出空间


I have a grid and two columns in it.. I place an expander in the second column... based on expanding or collapsing it, the width of the first column should vary. To be more specific, the contents in the first grid should occupy the whole window when the expander is in collapsed state and when expanded, the first column width should get adjusted to give space for the contents in the expander


<Window x:Class="GridSplitterExample.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Width="1200">
    <Grid Style="{DynamicResource BaseGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="900"/>
            <ColumnDefinition Width="300"/>
        </Grid.ColumnDefinitions>
        <Grid Width="1100">
            <GroupBox Header="Variable section" Width="1100"/>
        </Grid>
        <Grid Grid.Column="2">
            <Expander  ExpandDirection="Left" ToolTip="Show/Hide TaskPanel">
                <GroupBox Header="Expander section" Width="300"/>
            </Expander>
        </Grid>
    </Grid>
</Window>



如果扩展器被折叠,则组框中内容的大小也应占据整个窗口,如果扩展器被扩展,则应缩小整个窗口.



The size of the contents in the groupbox also should occupy the whole window if expander is collapsed and shrink if expander is expanded

推荐答案

在宽度中仅使用"*"(而不是硬编码的900值).
将300宽度设置为自动".

试试
Just use "*" in the width (instead of the hardcoded 900 value).
Make the 300 width "Auto".

Try
<columndefinition width="*" />
<columndefinition width="Auto" />


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

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