объект MaxSize автоматически настраивается на изменение размера окна - PullRequest
0 голосов
/ 06 марта 2019

Как мне настроить MaxHeight, MaxWidth моих TreeView и MaxWidth из TextBlock для изменения размера моего окна?(XXX значения в предварительном просмотре)

<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>
        <TreeView MaxHeight="XXX" MaxWidth="XXX">
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type local:TreeParentClass}" ItemsSource="{Binding TreeParentMembers}">
                    <TextBlock MaxWidth="XXX"/>
                </HierarchicalDataTemplate>
            </TreeView.Resources>
        </TreeView>    
    </Grid>
</Window>

1 Ответ

0 голосов
/ 06 марта 2019

Если все, что вам нужно, - это чтобы размер дерева отображался с окном, вы можете использовать определения строк и столбцов сетки.

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...