wpf - TreeView 不拉伸(stretch)

标签 wpf xaml treeview

我有一个简单的应用程序,它有一个 Treeview 和一个网格中的主要内容区域。网格有一个 gridsplitter 来调整大小,但这不会调整 Treeview 的大小。

enter image description here

我读到这是一个错误,

but what is the simplest way to resize the Treeview?

<Window x:Class="TestGridSplitter.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="5"/>
        <ColumnDefinition />                              
    </Grid.ColumnDefinitions>
    <TreeView Grid.Column="0">
        <TreeViewItem>
            My Treeview
        </TreeViewItem>
    </TreeView>
    <GridSplitter Grid.Column="1" Width="5"/>
    <TextBlock Grid.Column="2">
        Main Content Area
    </TextBlock>
</Grid>

将水平对齐或内容对齐设置为拉伸(stretch),不起作用!

最佳答案

此外,还需要设置 GridSplitter 的其他属性,例如 ResizeDirection="Columns"ResizeBehavior="PreviousAndNext" 属性。例如:

<GridSplitter Grid.Column="1" Width="5" ResizeDirection="Columns"  
                                 ResizeBehavior="PreviousAndNext"/>

关于wpf - TreeView 不拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573643/

相关文章:

c# - 数据绑定(bind)到异构列表

c# - 基于动态资源的样式

c# - WPF框架如何处理MVVM中属性的循环更新?

c# - 如何在 Windows 通用应用程序 (Windows 10) 中的 markdowntextblock 中格式化聊天对话

asp.net - 删除 Asp.Net 中 TreeViewNode 的节点缩进

c# - 如何在我的 WPF 项目中导入 windows.media.capture?

wpf VisualState 与 wpfToolkit 冲突?

c# - Windows Phone 8 View 模型绑定(bind)

Python 3 和 Gtk+3 - TreeView 和行的替代颜色问题

javascript - 根据条件为 Odoo10 中的复选框添加颜色