对象MaxSize自动调整为更改窗口大小

时间:2019-03-06 16:28:18

标签: c# wpf xaml

如何调整MaxHeight的{​​{1}},MaxWidthTreeView的{​​{1}}以适应窗口的大小? (预览中的XXX个值)

MaxWidth

1 个答案:

答案 0 :(得分:0)

如果只需要使用窗口来调整树视图的大小,则可以使用网格行和列定义。

<Window x:Class="MyApplication.MyWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:MyApplication"
         Height="450" Width="800">
  <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="2*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="3*"/>
    </Grid.ColumnDefinitions>

    <TreeView x:Name="myTreeView" Background="SteelBlue" Grid.Row="0" Grid.Column="0">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="DataType="{x:Type local:TreeParentClass}" 
                                      ItemsSource="{Binding TreeParentMembers}">
                <TextBlock Text="{Binding Title}"/>
            </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>

    <Border Background="DarkGray" Grid.Row="1" Grid.Column="0"/>
    <Border Background="LightCoral" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"/>
  </Grid>
</Window>