该公司具有传统的复杂的组织结构、限定金额的级别使用的字母'n',而不是实际数量。我会试着快速的结构,我是在努力实现在单间隔的字体:

         Alice
 ,--------|-------,------,------,
Bob      Fred    Jack   Kim    Lucy
 |        |      
Charlie  Greg    
Darren   Henry
Eric

正如你可以看到这是不对称的,杰克,Kim和露西的报告,爱丽丝,但没有报告自己。

使用 TreeView 有一个 ItemsPanel 含有一个 StackPanelOrientation="Horizontal"足够容易, 但这可能导致一个非常大的 TreeView 一旦有些人拥有20人报告他们!你可以 还使用 Triggers 来看看是否 TreeViewItem 有的儿童 Property="TreeViewItem.HasItems", 但这不是在同样的背景下为前提到的 ItemsPanel. 例如:我可以告诉,弗雷德有报告,但不是他们是否有报告自己。

所以,你可以有条件的格式 TreeViewItems 是垂直的,如果他们没有自己的孩子?

有帮助吗?

解决方案 2

我没有最终使用技巧相联系的文章,这我已经读通过,但并不认为会帮助我。

肉,它发生在这里,在一个变换器:

<ValueConversion(GetType(ItemsPresenter), GetType(Orientation))> _
Public Class ItemsPanelOrientationConverter
Implements IValueConverter

Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, _
ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) _
As Object Implements System.Windows.Data.IValueConverter.Convert

    'The 'value' argument should reference an ItemsPresenter.'
    Dim itemsPresenter As ItemsPresenter = TryCast(value, ItemsPresenter)
    If itemsPresenter Is Nothing Then
        Return Binding.DoNothing
    End If

    'The ItemsPresenter''s templated parent should be a TreeViewItem.'
    Dim item As TreeViewItem = TryCast(itemsPresenter.TemplatedParent, TreeViewItem)
    If item Is Nothing Then
        Return Binding.DoNothing
    End If

    For Each i As Object In item.Items
        Dim element As StaffMember = TryCast(i, StaffMember)
        If element.IsManager Then
            'If this element has children, then return Horizontal'
            Return Orientation.Horizontal
        End If
    Next

    'Must be a stub ItemPresenter'
    Return Orientation.Vertical

End Function

这反过来获得消耗的风格我创造了树视图:

    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate >
                <ItemsPanelTemplate.Resources>
                    <local:ItemsPanelOrientationConverter x:Key="conv" />
                </ItemsPanelTemplate.Resources>
                <StackPanel IsItemsHost="True" 
                            Orientation="{Binding   
                            RelativeSource={x:Static RelativeSource.TemplatedParent}, 
                            Converter={StaticResource conv}}" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>

其他提示

乔希*史密斯有一个excecllent演示文中关于树视图.读它 在这里,

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top