调整应用程序控件以适合窗口大小

时间:2014-06-23 17:16:35

标签: c# wpf

我需要调整控件的高度trvMenuStackPanel (Grid.Column="1")StackPanel(Grid.Column="3")高度+宽度tabControl(宽度到左边)。我只需要它们在运行时适合应用程序窗口的大小,例如全屏。这是xaml:

<Window x:Class="DiagramDesigner.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    ...
                    <TreeView Name="trvMenu" HorizontalAlignment="Left" Height="312" 
                         ...                                                   
                    </TreeView>
                ...
                    <StackPanel Grid.Column="1">
                        ...
                    </StackPanel>
                </Border>
                ...
                <TabControl x:Name="tabControl" Grid.Column="2" SelectionChanged="tabDynamic_SelectionChanged" ItemsSource="{Binding}">
                    ...
                </TabControl>
                <StackPanel  Grid.Column="3">
                ...
                </StackPanel>
            ...

1 个答案:

答案 0 :(得分:0)

答案是首先根据应用程序的结构构建网格,并且需要调整到窗口大小的每个列或行应该具有:

<Grid.RowDefinitions>
        ...
        <RowDefinition Height="*" />
        ...
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
       ...
       <ColumnDefinition Width="*"/>
       ...
</Grid.ColumnDefinitions>