在TreeView中使用WrapPanel [英] Using A WrapPanel in a TreeView

查看:88
本文介绍了在TreeView中使用WrapPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示详细程度的数据,所以我使用TreeView,但是每个细节都很短,所以我想使用WrapPanel(水平)在每行显示许多细节.

I want to display data with level of detail, so i use a TreeView, but each detail is quite short, so i would like to use a WrapPanel (horizontal) to have many details per line.

类似的东西:

  • 这是未展开的项目

  • This is an unexpanded item

这是展开项目的标题

信息1信息2信息3信息4

Info 1 Info 2 Info 3 Info 4

信息5信息6信息7

所以我尝试定义TreeViewItem的模板,但无法将包装面板放到 裹.当信息的datatemplate宽度为100并且TreeView时,我每行只有一个信息 是500.我尝试设置WrapPanel的宽度,ItemsWidth,以及其他没有成功的东西.

So i tried defining TreeViewItem's Template but i could not get the wrappanel to wrap. I have only one info per line, when info's datatemplate width is 100 and TreeView is 500. i tried setting Width of WrapPanel, ItemsWidth, are other things with no success.

有什么主意吗?

我终于有了一个更简单"的解决方案.看来我们 必须定义WrapPanel的宽度,这会使解决方案的通用性降低.

EDIT : i finally got this to work with a 'simpler' solution. Still it seems that we have to define the WrapPanel's Width, which make the solution less generic.

这是我想到的解决方案:仅以一种样式定义在 TreeViewItem:

Here's the solution i came to : just defining, in a style, the ItemsPanel used in a TreeViewItem :

<Style TargetType="TreeViewItem">
   <Setter Property="ItemsPanel">
       <Setter.Value>
              <ItemsPanelTemplate>
                <WrapPanel  Orientation="Horizontal"      
                            Width="520"
                            HorizontalAlignment="Stretch" 
                            Margin="0" 
                            ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                            IsItemsHost="True"  
                    />
              </ItemsPanelTemplate>
       </Setter.Value>
   </Setter>
</Style>

为了完整起见,我仍然在这里让无法使用的解决方案. (为什么它不起作用???)

And i still let the not working solution here, for completeness sake. (Why wouldn't it work ???)

    <Style TargetType="TreeViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TreeViewItem">
                <Grid Margin="2" Width="500">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <ContentPresenter Name="PART_Header"                 
                                      ContentSource="Header"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center" />

    !!!! this is the wrapanel not wrapping 
                    <ListBox     Name="AllItems"     Grid.Row="1"      >
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel  Orientation="Horizontal"   />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ItemsPresenter   />
                    </ListBox>

                </Grid> 

                <ControlTemplate.Triggers>
                    <Trigger Property="IsExpanded" Value="False">
                        <Setter
                                       TargetName="AllItems"
                                        Property="Visibility"                     
                                          Value="Collapsed" />
                  </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

推荐答案

我终于将其与更简单"的解决方案一起使用.看来我们 必须定义WrapPanel的宽度,这会使解决方案的通用性降低. (也许绑定宽度(但是用哪个?)可以解决这个问题)

EDIT : i finally got this to work with a 'simpler' solution. Still it seems that we have to define the WrapPanel's Width, which make the solution less generic. (Maybe a binding of the width (but which ?) would solve this)

这是我想到的解决方案:仅以一种样式定义在 TreeViewItem:

Here's the solution i came to : just defining, in a style, the ItemsPanel used in a TreeViewItem :

<Style TargetType="TreeViewItem">
   <Setter Property="ItemsPanel">
       <Setter.Value>
              <ItemsPanelTemplate>
                <WrapPanel  Orientation="Horizontal"      
                            Width="520"
                            HorizontalAlignment="Stretch" 
                            Margin="0" 
                            ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                            IsItemsHost="True"  
                    />
              </ItemsPanelTemplate>
       </Setter.Value>
   </Setter>
</Style>

这篇关于在TreeView中使用WrapPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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