我期待在一個結構複雜,我似乎無法找到一種方法來顯示它...WPF複雜的分級數據模板
我的情況:
類:里程碑2所列出內部,其他子目錄列表和活動列表。
所以結構可能是這樣的:
M1
- 里程碑
- SubMilestone
- 里程碑
- 活動
- Submilestone
- SubMilestone
- 活動
任何人有任何的想法是如何建立的?或者可以將我推向一個方向?
回答我的問題
<TreeView ItemsSource="{Binding Path=Project.TrackList}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type deto:Track}" ItemsSource="{Binding Path=FaseList}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=TrackType}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type deto:Fase}" ItemsSource="{Binding Path=MilestoneList}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=FaseType}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type deto:Milestone}" ItemsSource="{Binding Converter={StaticResource MConverter}}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Description}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type deto:Activity}" ItemsSource="{Binding Path=ActivityList}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Description}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
和轉換器:
public class MilestoneConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var m = value as Milestone;
CompositeCollection collection = new CompositeCollection();
collection.Add(new CollectionContainer()
{
Collection = m.MilestoneList
});
collection.Add(new CollectionContainer()
{
Collection = m.ActivityList
});
return collection;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
聰明的方式來避免上下文問題 - 非常有幫助,謝謝! – Doug 2013-05-23 14:51:46