嗯,我回答了我自己的問題,但我不認爲這是正確的方式去做這件事。
我在樹形視圖上使用了一個itemtemplate,然後在該模板中創建了另一個樹視圖,並在其上添加了另一個itemtemplate。
但是,我可以理解這一點,當我看着它看着HierarchicalDataTemplates。
WPF:
<TreeView HorizontalAlignment="Left" Name="treeView1" VerticalAlignment="Top">
<TreeView.ItemTemplate>
<DataTemplate>
<TreeViewItem Header="{Binding FileName}">
<TextBlock Text="{Binding MetaData1}"/>
<TextBlock Text="{Binding MetaData2}"/>
<TreeViewItem ItemsSource="{Binding Mappings}" Header="Mappings">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Original}" Grid.Column="0"/>
<TextBlock Text="->" Grid.Column="1" Margin="3,0,3,0"/>
<TextBlock Text="{Binding Mapping}" Grid.Column="2"/>
</Grid>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
類:
public class ClassA
{
public string MetaData1 { get; set; }
public string MetaData2 { get; set; }
public string FileName { get; set; }
public List<ClassB> Mappings { get; set; }
}
public class ClassB
{
public string Original { get; set; }
public string Mapping { get; set; }
}
快捷我的數據結構的實現:
new List<ClassA>
{
new ClassA
{
FileName = "ClassA 1",
MetaData1 = "Prop 1",
MetaData2 = "Prop 2",
Mappings = new List<ClassB>
{
new ClassB
{
Original = "BProp 1",
Mapping = "BProp 2"
}
}
},
new ClassA
{
FileName = "ClassA 2",
MetaData1 = "Prop 1",
MetaData2 = "Prop 2",
Mappings = new List<ClassB>
{
new ClassB
{
Original = "BProp 1",
Mapping = "BProp 2"
}
}
}
};
如果有誰知道我應該怎麼做了這更好的(與HierachicalDataTemplates和DataTemplates我可以看到該代碼並對此進行改進。