0
多個列表
我的模型是像這樣:WPF的TreeView中HierarchicalDataTemplate
public class CPFF
{
public CMC Cmc { get; set; }
}
public class CMC
{
public List<CMCRecord> recordList { get; set; }
}
public class CMCRecord
{
public string name { get; set; }
public List<param> recordHeader { get; set; }
public List<param> paramList { get; set; }
public List<CmcStruct> structList { get; set; }
public bool IsEmptyRecord { get; set; }
public CpffConsts.CpffProjectVersion cpffProjectVersion { get; set; }
}
這是我的XAML:
<TreeView DataContext="{Binding Cpff1StProjectObject}" SelectedItemChanged="TreeView_OnSelectedItemChanged" HorizontalContentAlignment="Stretch" >
<TreeViewItem Header="CMC" >
<TreeViewItem Header="RecordList" ItemsSource="{Binding Cmc.recordList}" >
<HierarchicalDataTemplate DataType="{x:Type types:CMCRecord}" ItemsSource="{Binding paramList}">
<TextBlock Text="{Binding Path=name, StringFormat={}CMCRecord : {0}}" />
</HierarchicalDataTemplate>
</TreeViewItem>
</TreeViewItem>
</TreeView>
<HierarchicalDataTemplate DataType="{x:Type types:param}">
<StackPanel>
<TextBlock Text="{Binding Path=name, StringFormat={}Name : {0}}" />
<TextBlock Text="{Binding Path=type, StringFormat={}Type : {0}}" />
<TextBlock Text="{Binding Path=description, StringFormat={}Description : {0}}" />
<TextBlock Text="{Binding Path=defaultValue, StringFormat={}DefaultValue : {0}}" />
<TextBlock Text="{Binding Path=domain_name, StringFormat={}domain_name : {0}}" />
<TextBlock Text="{Binding Path=notes, StringFormat={}Notes : {0}}" />
<TextBlock Text="{Binding Path=offset, StringFormat={}Offset : {0}}" />
<TextBlock Text="{Binding Path=bytes, StringFormat={}Bytes : {0}}" />
<TextBlock Text="{Binding Path=size, StringFormat={}Size : {0}}" />
<TextBlock Text="{Binding Path=min, StringFormat={}Min : {0}}" />
<TextBlock Text="{Binding Path=max, StringFormat={}Max : {0}}" />
</StackPanel>
</<HierarchicalDataTemplate DataType="{x:Type types:param}">
<StackPanel>
<TextBlock Text="{Binding Path=name, StringFormat={}Name : {0}}" />
<TextBlock Text="{Binding Path=type, StringFormat={}Type : {0}}" />
<TextBlock Text="{Binding Path=description, StringFormat={}Description : {0}}" />
<TextBlock Text="{Binding Path=defaultValue, StringFormat={}DefaultValue : {0}}" />
<TextBlock Text="{Binding Path=domain_name, StringFormat={}domain_name : {0}}" />
<TextBlock Text="{Binding Path=notes, StringFormat={}Notes : {0}}" />
<TextBlock Text="{Binding Path=offset, StringFormat={}Offset : {0}}" />
<TextBlock Text="{Binding Path=bytes, StringFormat={}Bytes : {0}}" />
<TextBlock Text="{Binding Path=size, StringFormat={}Size : {0}}" />
<TextBlock Text="{Binding Path=min, StringFormat={}Min : {0}}" />
<TextBlock Text="{Binding Path=max, StringFormat={}Max : {0}}" />
</StackPanel>
</HierarchicalDataTemplate>>
這是我的樹看起來怎麼樣:
由於CM CRecord包含多個列表,我想將其反映到工具中。 但是由於HierarchicalDataTemplate中的ItemSource綁定到參數列表,因此我如何在TreeView中顯示多個列表?