|
<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
x:Class="Microsoft.Windows.Controls.Samples.NestedHierarchicalDataTemplateSample">
<StackPanel>
<StackPanel.Resources>
<!-- HierarchicalDataTemplates -->
<controls:HierarchicalDataTemplate x:Key="songEntry">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock FontStyle="Italic" Text="{Binding Path=Title}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
<controls:HierarchicalDataTemplate x:Key="albumEntry" ItemsSource="{Binding Path=Songs}" ItemTemplate="{StaticResource songEntry}">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock Text="{Binding Path=Title}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
<controls:HierarchicalDataTemplate x:Key="artistEntry" ItemsSource="{Binding Path=Albums}" ItemTemplate="{StaticResource albumEntry}">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock FontWeight="Bold" Text="{Binding Path=ArtistName}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
</StackPanel.Resources>
<ContentControl Content="Nesting HierarchicalDataTemplates" Style="{StaticResource Header}" />
<TextBlock Style="{StaticResource Information}">
This shows how to nest HierarchicalDataTemplates for when you want
each level of your tree to have its own DataTemplate and associated styling.
</TextBlock>
<controls:TreeView x:Name="ArtistTree" ItemTemplate="{StaticResource artistEntry}" />
<src:SourceViewer xmlns:src="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<src:SourceFile Path="NestedHierarchicalDataTemplateSample.xaml">
<src:SourceFile.Source>
<sys:String><!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
x:Class="Microsoft.Windows.Controls.Samples.NestedHierarchicalDataTemplateSample">
<StackPanel>
<StackPanel.Resources>
<!-- HierarchicalDataTemplates -->
<controls:HierarchicalDataTemplate x:Key="songEntry">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock FontStyle="Italic" Text="{Binding Path=Title}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
<controls:HierarchicalDataTemplate x:Key="albumEntry" ItemsSource="{Binding Path=Songs}" ItemTemplate="{StaticResource songEntry}">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock Text="{Binding Path=Title}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
<controls:HierarchicalDataTemplate x:Key="artistEntry" ItemsSource="{Binding Path=Albums}" ItemTemplate="{StaticResource albumEntry}">
<StackPanel Orientation="Horizontal">
<ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" />
<TextBlock FontWeight="Bold" Text="{Binding Path=ArtistName}" />
</StackPanel>
</controls:HierarchicalDataTemplate>
</StackPanel.Resources>
<ContentControl Content="Nesting HierarchicalDataTemplates" Style="{StaticResource Header}" />
<TextBlock Style="{StaticResource Information}">
This shows how to nest HierarchicalDataTemplates for when you want
each level of your tree to have its own DataTemplate and associated styling.
</TextBlock>
<controls:TreeView x:Name="ArtistTree" ItemTemplate="{StaticResource artistEntry}" />
</StackPanel>
</UserControl></sys:String>
</src:SourceFile.Source>
</src:SourceFile>
<src:SourceFile Path="NestedHierarchicalDataTemplateSample.xaml.cs">
<src:SourceFile.Source>
<sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.Windows.Controls;
using System.ComponentModel;
namespace Microsoft.Windows.Controls.Samples
{
/// <summary>
/// The NestedHierarchicalDataTemplate sample page shows how to nest
/// HierarchicalDataTemplate templates with each HierarchicalDataTemplate
/// having its own unique template.
/// </summary>
[Sample("Nested HierarchicalDataTemplate", DifficultyLevel.Scenario)]
[Category("TreeView")]
public partial class NestedHierarchicalDataTemplateSample : UserControl
{
/// <summary>
/// Initializes a new instance of the
/// NestedHierarchicalDataTemplateSample class.
/// </summary>
public NestedHierarchicalDataTemplateSample()
{
InitializeComponent();
ArtistTree.ItemsSource = Artist.AllArtists;
}
}
}</sys:String>
</src:SourceFile.Source>
</src:SourceFile>
</src:SourceViewer>
</StackPanel>
</UserControl>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.