我正在使用树视图,当它加载时,它将HierarchicalDataTemplates显示为对象,而不是显示它们持有的视图模型。
截图:
XAML:
<TreeView Name="ProductionTree" HorizontalAlignment="Left" Height="255" Margin="10,41,0,0" VerticalAlignment="Top" Width="281" SelectedItemChanged="TreeView_SelectedItemChanged" >
<HierarchicalDataTemplate
ItemsSource="{Binding Path=ProductionRuns}" >
<StackPanel Orientation="Horizontal">
<Grid Margin="2" Height="24">
<TextBlock Margin="2" Text="{Binding Path=Name}" VerticalAlignment="Center" FontWeight="Bold" />
</Grid>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
ItemsSource="{Binding Path=ProductionRuns.Containers}" >
<StackPanel Orientation="Horizontal">
<Grid Margin="2" Height="24">
<TextBlock Margin="2" Text="{Binding Path=Name}" VerticalAlignment="Center" FontWeight="Bold" />
</Grid>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
ItemsSource="{Binding Path=ProductionRuns.Containers.Samples}" >
<StackPanel Orientation="Horizontal">
<Grid Margin="2" Height="24">
<TextBlock Margin="2" Text="{Binding Path=Name}" VerticalAlignment="Center" FontWeight="Bold" />
</Grid>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
ItemsSource="{Binding ProductionRuns.Containers.Samples.Tests}" >
<StackPanel Orientation="Horizontal">
<Grid Margin="2" Height="24">
<TextBlock Margin="2" Text="{Binding Path=Name}" VerticalAlignment="Center" FontWeight="Bold" />
</Grid>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView>