Treeview将HierarchicalDataTemplate显示为对象

时间:2015-05-08 13:31:22

标签: c# wpf mvvm

我正在使用树视图,当它加载时,它将HierarchicalDataTemplates显示为对象,而不是显示它们持有的视图模型。

截图:

enter image description here

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>

0 个答案:

没有答案