wpf 中借助 Grid 实现随着 Form 大小变化而按比例自动改变宽度或高度。

    <DockPanel>
        <Grid DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Height="280">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="47*"/>
                <ColumnDefinition Width="6*" MinWidth="35"/>
                <ColumnDefinition Width="47*"/>
            </Grid.ColumnDefinitions>

<TreeView Margin="10,0,0,10" Grid.Row="1"/>

 

Grid 置于 DockPanel 中

设置第一行的高度为30,第二行的高度为 Grid.Height-30

设置第一、三列为 Grid 的宽度的 47% ,第二列为 6%,最小为35

将控件置于Cell之中

 

posted @ 2013-03-18 22:54  I'm CY  阅读(4066)  评论(0编辑  收藏  举报