更改 TreeView ItemsPanel 方向无效 [英] Changing the TreeView ItemsPanel orientation has no effect

查看:22
本文介绍了更改 TreeView ItemsPanel 方向无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TreeView 的默认 ItemsPanel 是具有默认方向 VerticalStackPanel.我已将 StackPanel 的方向更改为 Horizo​​ntal:

The default ItemsPanel of a TreeView is a StackPanel that has the default orientation Vertical. I have changed the orientation of the StackPanel to Horizontal:

<controls:TreeView>
  <controls:TreeView.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
  </controls:TreeView.ItemsPanel>
  <controls:TreeViewItem Header="Root" IsExpanded="True">
    <controls:TreeViewItem Header="Alfa"/>
    <controls:TreeViewItem Header="Beta"/>
    <controls:TreeViewItem Header="Gamma"/>
  </controls:TreeViewItem>
</controls:TreeView>

我希望树中的下级项目水平堆叠而不是垂直堆叠,但是当我将方向从 Vertical 交换到 Horizo​​ntal 并返回时,我看不到任何明显变化再次.为什么StackPanelOrientation 不影响ItemsPresenter 中项目的布局?

I would expect the subordinate items in the tree to stack horizontally instead of vertically, but I see no visible change when I swap the orientation from Vertical to Horizontal and back again. Why doesn't the Orientation of the StackPanel affect the layout of the items in the ItemsPresenter?

推荐答案

Jeff Wilcox 的评论让我思考并找出我做错了什么.我正在修改 TreeViewItemsPanel,但是为了达到我想要的效果,我必须修改 TreeViewItemItemsPanel代码>:

Jeff Wilcox' comment got me thinking and I figured out what I did wrong. I was modifying the ItemsPanel of the TreeView, but to achieve what I wanted I had to modify the ItemsPanel of the TreeViewItem:

<controls:TreeView>
  <controls:TreeView.ItemContainerStyle>
    <Style TargetType="controls:TreeViewItem">
      <Setter Property="ItemsPanel">
        <Setter.Value>
          <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
          </ItemsPanelTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </controls:TreeView.ItemContainerStyle>
  <controls:TreeViewItem Header="Root" IsExpanded="True">
    <controls:TreeViewItem Header="Alfa"/>
    <controls:TreeViewItem Header="Beta"/>
    <controls:TreeViewItem Header="Gamma"/>
  </controls:TreeViewItem>
</controls:TreeView>

这篇关于更改 TreeView ItemsPanel 方向无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆