[英]TreeTable control in WPF and c#
我想知道如何在具有树结构的数据网格中显示分层数据。 我会在场景中阐明自己
我有以下课程。
public class Package
{
public String name { get; set; }
public Measure measure { get; set; }
public List<Class> classList { get; set; }
}
public class Class
{
public String name { get; set; }
public Measure measure { get; set; }
public List<Method> methodsList { get; set; }
}
public class Method
{
public String name { get; set; }
public Measure measure { get; set; }
}
public class Measure
{
public String tolc { get; set; }
public String lloc { get; set; }
public String ploc { get; set; }
public String lComments { get; set; }
public String blankLines { get; set; }
}
现在,我想在具有这样的树结构的数据网格中显示它们。
Item Name TLOC LLOC PLOC LCOMMENTS BLANKLINES
package1 100 80 70 45 30
-class1 30 20 19 2 12
--method1 30 20 19 2 12
-class2 70 60 51 43 18
--method1 50 20 11 23 8
--method2 20 40 40 20 10
package2 50 20 10 5 5
-class 50 20 10 5 5
希望我说清楚。 如何在C#中使用WPF完成此操作。
这将非常有帮助,这让我现在快疯了。
您需要在XAML中使用CollectionViewSource,如下所示:
<CollectionViewSource x:Key="Packages" Source="{Binding AllCode}">
<CollectionViewSource.SortDescriptions>
<!-- Requires 'xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"' declaration. -->
<scm:SortDescription PropertyName="Name"/>
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="PackageName"/>
<PropertyGroupDescription PropertyName="ClassName"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
然后,您需要使用组样式的附魔数据网格:
<DataGrid x:Name="dataGrid1"
Background="{x:Null}"
ItemsSource="{Binding Source={StaticResource Packages}}"
<DataGrid.Columns>
<DataGridTextColumn DisplayMemberPath="PackageName"/>
<DataGridTextColumn DisplayMemberPath="ClassName"/>
</DataGrid.Columns>
<DataGrid.GroupStyle>
<!-- Style for groups at top level. -->
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True" Background="White">
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold" Text="{Binding Name}" Margin="5,0"/>
<TextBlock FontWeight="Bold" Text="{Binding ItemCount}" Margin="5,0"/>
</DockPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
</DataGrid>
我没有测试,所以希望您有想法。 如果没有,请告诉我。 我尝试解释更多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.