HierarchicalDataTemplate Classe
Definizione
Rappresenta un oggetto DataTemplate che supporta HeaderedItemsControl, ad esempio TreeViewItem o MenuItem.Represents a DataTemplate that supports HeaderedItemsControl, such as TreeViewItem or MenuItem.
public ref class HierarchicalDataTemplate : System::Windows::DataTemplate
public class HierarchicalDataTemplate : System.Windows.DataTemplate
type HierarchicalDataTemplate = class
inherit DataTemplate
Public Class HierarchicalDataTemplate
Inherits DataTemplate
- Ereditarietà
Esempio
Nell'esempio seguente ListLeagueList
è un elenco di oggetti League
.In the following example, ListLeagueList
is a list of League
objects. Ogni oggetto League
ha un Name
e una raccolta di oggetti Division
.Each League
object has a Name
and a collection of Division
objects. Ogni Division
ha un Name
e una raccolta di oggetti Team
e ogni oggetto Team
ha un Name
.Each Division
has a Name
and a collection of Team
objects, and each Team
object has a Name
.
<Window x:Class="SDKSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HierarchicalDataTemplate Sample"
xmlns:src="clr-namespace:SDKSample">
<DockPanel>
<DockPanel.Resources>
<src:ListLeagueList x:Key="MyList"/>
<HierarchicalDataTemplate DataType = "{x:Type src:League}"
ItemsSource = "{Binding Path=Divisions}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType = "{x:Type src:Division}"
ItemsSource = "{Binding Path=Teams}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type src:Team}">
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</DockPanel.Resources>
<Menu Name="menu1" DockPanel.Dock="Top" Margin="10,10,10,10">
<MenuItem Header="My Soccer Leagues"
ItemsSource="{Binding Source={StaticResource MyList}}" />
</Menu>
<TreeView>
<TreeViewItem ItemsSource="{Binding Source={StaticResource MyList}}" Header="My Soccer Leagues" />
</TreeView>
</DockPanel>
</Window>
Nell'esempio viene mostrato che, con l'utilizzo di HierarchicalDataTemplate , è possibile visualizzare facilmente i dati dell'elenco che contengono altri elenchi.The example shows that with the use of HierarchicalDataTemplate, you can easily display list data that contains other lists. Lo screenshot seguente mostra l'esempio.The following is a screenshot of the example.
Costruttori
HierarchicalDataTemplate() |
Inizializza una nuova istanza della classe HierarchicalDataTemplate.Initializes a new instance of the HierarchicalDataTemplate class. |
HierarchicalDataTemplate(Object) |
Inizializza una nuova istanza della classe HierarchicalDataTemplate con il tipo specificato a cui è destinato il modello.Initializes a new instance of the HierarchicalDataTemplate class with the specified type for which the template is intended. |
Proprietà
AlternationCount |
Ottiene o imposta il numero di contenitori di elementi alternati per gli elementi figlio.Gets or sets the number of alternating item containers for the child items. |
DataTemplateKey |
Ottiene la chiave predefinita di DataTemplate.Gets the default key of the DataTemplate. (Ereditato da DataTemplate) |
DataType |
Ottiene o imposta il tipo per cui l'oggetto DataTemplate è destinato.Gets or sets the type for which this DataTemplate is intended. (Ereditato da DataTemplate) |
Dispatcher |
Ottiene l'oggetto Dispatcher associato a DispatcherObject.Gets the Dispatcher this DispatcherObject is associated with. (Ereditato da DispatcherObject) |
HasContent |
Ottiene un valore che indica se il contenuto di questo modello è stato ottimizzato.Gets a value that indicates whether this template has optimized content. (Ereditato da FrameworkTemplate) |
IsSealed |
Ottiene un valore che indica se questo oggetto è in uno stato immutabile e pertanto non può essere modificato.Gets a value that indicates whether this object is in an immutable state so it cannot be changed. (Ereditato da FrameworkTemplate) |
ItemBindingGroup |
Ottiene o imposta l'oggetto BindingGroup copiato in ogni elemento figlio.Gets or sets the BindingGroup that is copied to each child item. |
ItemContainerStyle |
Ottiene o imposta l'oggetto Style applicato al contenitore di elementi per ogni elemento figlio.Gets or sets the Style that is applied to the item container for each child item. |
ItemContainerStyleSelector |
Ottiene o imposta la logica della selezione in base allo stile personalizzata per uno stile che può essere applicato a ogni contenitore di elementi.Gets or sets custom style-selection logic for a style that can be applied to each item container. |
ItemsSource |
Ottiene o imposta l'associazione per questo modello di dati, che indica dove trovare la raccolta che rappresenta il livello successivo nella gerarchia dei dati.Gets or sets the binding for this data template, which indicates where to find the collection that represents the next level in the data hierarchy. |
ItemStringFormat |
Ottiene o imposta una stringa composita che specifica come formattare gli elementi nel livello successivo nella gerarchia di dati se vengono visualizzati come stringhe.Gets or sets a composite string that specifies how to format the items in the next level in the data hierarchy if they are displayed as strings. |
ItemTemplate |
Ottiene o imposta l'oggetto DataTemplate da applicare alla proprietà ItemTemplate in un oggetto HeaderedItemsControl generato, ad esempio un oggetto MenuItem o TreeViewItem, per indicare come visualizzare gli elementi del livello successivo nella gerarchia dei dati.Gets or sets the DataTemplate to apply to the ItemTemplate property on a generated HeaderedItemsControl (such as a MenuItem or a TreeViewItem), to indicate how to display items from the next level in the data hierarchy. |
ItemTemplateSelector |
Ottiene o imposta l'oggetto DataTemplateSelector da applicare alla proprietà ItemTemplateSelector in un oggetto HeaderedItemsControl generato, ad esempio un oggetto MenuItem o TreeViewItem, per indicare come selezionare un modello per visualizzare gli elementi del livello successivo nella gerarchia dei dati.Gets or sets the DataTemplateSelector to apply to the ItemTemplateSelector property on a generated HeaderedItemsControl (such as a MenuItem or a TreeViewItem), to indicate how to select a template to display items from the next level in the data hierarchy. |
Resources |
Ottiene o imposta l'insieme di risorse che possono essere utilizzate all'interno dell'ambito di questo modello.Gets or sets the collection of resources that can be used within the scope of this template. (Ereditato da FrameworkTemplate) |
Template |
Ottiene o imposta un riferimento all'oggetto che registra o riproduce i nodi XAML per il modello quando il modello è definito o è applicato da un writer.Gets or sets a reference to the object that records or plays the XAML nodes for the template when the template is defined or applied by a writer. (Ereditato da FrameworkTemplate) |
Triggers |
Ottiene un insieme di trigger che applicano valori di proprietà o eseguono azioni in base a una o più condizioni.Gets a collection of triggers that apply property values or perform actions based on one or more conditions. (Ereditato da DataTemplate) |
VisualTree |
Ottiene o imposta il nodo radice del modello.Gets or sets the root node of the template. (Ereditato da FrameworkTemplate) |
Metodi
CheckAccess() |
Determina se il thread chiamante ha accesso a DispatcherObject.Determines whether the calling thread has access to this DispatcherObject. (Ereditato da DispatcherObject) |
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object. (Ereditato da Object) |
FindName(String, FrameworkElement) |
Trova l'elemento associato al nome specificato definito all'interno del modello.Finds the element associated with the specified name defined within this template. (Ereditato da FrameworkTemplate) |
GetHashCode() |
Funge da funzione hash predefinita.Serves as the default hash function. (Ereditato da Object) |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance. (Ereditato da Object) |
LoadContent() |
Carica il contenuto del modello come istanza di un oggetto e restituisce l'elemento radice del contenuto.Loads the content of the template as an instance of an object and returns the root element of the content. (Ereditato da FrameworkTemplate) |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object. (Ereditato da Object) |
RegisterName(String, Object) |
Registra una nuova coppia nome/oggetto nel namescope corrente.Registers a new name/object pair into the current name scope. (Ereditato da FrameworkTemplate) |
Seal() |
Blocca il modello affinché non possa essere modificato.Locks the template so it cannot be changed. (Ereditato da FrameworkTemplate) |
ShouldSerializeResources(XamlDesignerSerializationManager) |
Restituisce un valore che indica se i processi di serializzazione devono serializzare il valore della proprietà Resources sulle istanze di questa classe.Returns a value that indicates whether serialization processes should serialize the value of the Resources property on instances of this class. (Ereditato da FrameworkTemplate) |
ShouldSerializeVisualTree() |
Restituisce un valore che indica se i processi di serializzazione devono serializzare il valore della proprietà VisualTree sulle istanze di questa classe.Returns a value that indicates whether serialization processes should serialize the value of the VisualTree property on instances of this class. (Ereditato da FrameworkTemplate) |
ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object. (Ereditato da Object) |
UnregisterName(String) |
Rimuove un mapping nome/oggetto dal NameScope XAML.Removes a name/object mapping from the XAML namescope. (Ereditato da FrameworkTemplate) |
ValidateTemplatedParent(FrameworkElement) |
Controlla il padre basato su modelli rispetto a un insieme di regole.Checks the templated parent against a set of rules. (Ereditato da DataTemplate) |
VerifyAccess() |
Impone che il thread chiamante abbia accesso a DispatcherObject.Enforces that the calling thread has access to this DispatcherObject. (Ereditato da DispatcherObject) |
Implementazioni dell'interfaccia esplicita
INameScope.FindName(String) |
Restituisce un oggetto con il nome identificativo specificato.Returns an object that has the provided identifying name. (Ereditato da FrameworkTemplate) |
IQueryAmbient.IsAmbientPropertyAvailable(String) |
Esegue una query per determinare se una proprietà di ambiente specificata è disponibile nell'ambito corrente.Queries whether a specified ambient property is available in the current scope. (Ereditato da FrameworkTemplate) |