我有一个看起来像这样的数据库:
Locations [rootlevel]
Inspections [level1]
Areas [level1]
Inspections [level2]
所以每个位置可以有零个或多个检查和零个或多个区域,并且区域有零个或多个检查。检查的记录都具有 LocationID!=null 和 AreaID=null 或 !=null 以获取此层次结构。
我想在树视图中获取表中每个项目的所有名称作为导航。到目前为止,我可以得到
位置-->区域-->检查或
地点-->检查
我似乎无法让树视图层次结构显示我需要的东西。是否可以?我试图使用嵌套树视图作为层次结构中的一个项目来显示我想要的,但它不能正常工作。
Locations-->Areas-->Inspections 的 xml 代码
<!--NAVIGATION TREE HIERARCHICAL TEMPLATE-->
<common:HierarchicalDataTemplate x:Key="AssetManager" ItemsSource="{Binding Path=Areas}">
<!--START OF AREA OPTIONS TEMPLATE-->
<common:HierarchicalDataTemplate.ItemTemplate>
<common:HierarchicalDataTemplate ItemsSource="{Binding Path=Inspections}">
<!--START OF INSPECTION OPTIONS TEMPLATE-->
<common:HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/SearchICON2.png" Height="20" Width="20" />
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</DataTemplate>
</common:HierarchicalDataTemplate.ItemTemplate>
<!--END OF INSPECTION OPTIONS TEMPLATE-->
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/ManufacturingICON.png" Width="20" Height="20"/>
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</common:HierarchicalDataTemplate>
</common:HierarchicalDataTemplate.ItemTemplate>
<!--END OF AREA OPTIONS TEMPLATE-->
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/ManufacturingICON.png" Width="20" Height="20"/>
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</common:HierarchicalDataTemplate>
<!--END OF NAVIGATION TEMPLATE-->
用于位置的 xaml--> 检查
<!--NAVIGATION TREE HIERARCHICAL TEMPLATE-->
<common:HierarchicalDataTemplate x:Key="AssetManager" ItemsSource="{Binding Path=Inspections}">
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/ManufacturingICON.png" Width="20" Height="20"/>
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</common:HierarchicalDataTemplate>
</common:HierarchicalDataTemplate.ItemTemplate>
<!--END OF TEMPLATE-->
用于嵌套树视图的 xml
<!--NAVIGATION TREE HIERARCHICAL TEMPLATE-->
<common:HierarchicalDataTemplate x:Key="AssetManager" ItemsSource="{Binding Path=Areas}">
<!--START OF AREA OPTIONS TEMPLATE-->
<common:HierarchicalDataTemplate.ItemTemplate>
<common:HierarchicalDataTemplate ItemsSource="{Binding Path=Inspections}">
<!--START OF INSPECTION OPTIONS TEMPLATE-->
<common:HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/SearchICON2.png" Height="20" Width="20" />
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</DataTemplate>
</common:HierarchicalDataTemplate.ItemTemplate>
<!--END OF INSPECTION OPTIONS TEMPLATE-->
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/ManufacturingICON.png" Width="20" Height="20"/>
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
</common:HierarchicalDataTemplate>
</common:HierarchicalDataTemplate.ItemTemplate>
<!--END OF AREA OPTIONS TEMPLATE-->
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image Source="Assets/Resources/ImageResources/ManufacturingICON.png" Width="20" Height="20"/>
<TextBlock Margin="0,0,0,0" Text="{Binding Path=Name}"/>
</StackPanel>
<sdk:TreeView HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource locationInspectionsViewSource}}" Name="inspectionsTreeView" VerticalAlignment="Top" ItemTemplate="{StaticResource Level2}" BorderBrush="{x:Null}" Background="{x:Null}"/>
</StackPanel>
</common:HierarchicalDataTemplate>
<!--END OF NAVIGATION TEMPLATE-->
谢谢