-->![Control Control](/uploads/1/2/6/3/126311593/595552356.png)
![Control Control](/uploads/1/2/6/3/126311593/917489555.png)
![Control Control](/uploads/1/2/6/3/126311593/595552356.png)
Windows Presentation Foundation (WPF). I have a hiearchy I want to use in a treeview control. The closest approximation of my data is an organization chart. For your reference, you can using XamlWriter.Save method to get the build-in template of Control, the following is the control template of TreeView.
This topic describes the styles and templates for the TreeView control. You can modify the default ControlTemplate to give the control a unique appearance. For more information, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate.
TreeView Parts
The TreeView control does not have any named parts.
When you create a ControlTemplate for an TreeView, your template might contain a ItemsPresenter within a ScrollViewer. (The ItemsPresenter displays each item in the TreeView; the ScrollViewer enables scrolling within the control). If the ItemsPresenter is not the direct child of the ScrollViewer, you must give the ItemsPresenter the name,
ItemsPresenter
.- I'm relatively new to MVVM and WPF. I'm attempting to fill a TreeView control with a directory and it's files / subdirectories (in effect the contents of a zip file that I have unpacked) Following along after this SO question, I have the following class.
- WPF Layout by Content. A TreeViewItem control template to give the TreeView an Organization Chart look. Left and the TreeView with the TreeViewItem control.
- TreeView loses virtualization with overridden control template. However, when I tried overriding the TreeView's template, along with the inner ScrollViewer's template, virtualization disappeared. Data binding to SelectedItem in a WPF Treeview. Difference between Control Template and DataTemplate in WPF.
TreeView States
![Control Control](/uploads/1/2/6/3/126311593/917489555.png)
The following table lists the visual states for the TreeView control.
VisualState Name | VisualStateGroup Name | Description |
---|---|---|
Valid | ValidationStates | The control uses the Validation class and the HasError attached property is false . |
InvalidFocused | ValidationStates | The HasError attached property is true has the control has focus. |
InvalidUnfocused | ValidationStates | The HasError attached property is true has the control does not have focus. |
TreeViewItem Parts
The following table lists the named parts for the TreeViewItem control.
Part | Type | Description |
---|---|---|
PART_Header | FrameworkElement | A visual element that contains that header content of the TreeView control. |
TreeViewItem States
The following table lists the visual states for TreeViewItem control.
C# Wpf Treeview
VisualState Name | VisualStateGroup Name | Description |
---|---|---|
Normal | CommonStates | The default state. |
MouseOver | CommonStates | The mouse pointer is positioned over the TreeViewItem. |
Disabled | CommonStates | The TreeViewItem is disabled. |
Focused | FocusStates | The TreeViewItem has focus. |
Unfocused | FocusStates | The TreeViewItem does not have focus. |
Expanded | ExpansionStates | The TreeViewItem control is expanded. |
Collapsed | ExpansionStates | The TreeViewItem control is collapsed. |
HasItems | HasItemsStates | The TreeViewItem has items. |
NoItems | HasItemsStates | The TreeViewItem does not have items. |
Selected | SelectionStates | The TreeViewItem is selected. |
SelectedInactive | SelectionStates | The TreeViewItem is selected but not active. |
Unselected | SelectionStates | The TreeViewItem is not selected. |
Valid | ValidationStates | The control uses the Validation class and the HasError attached property is false . |
InvalidFocused | ValidationStates | The HasError attached property is true has the control has focus. |
InvalidUnfocused | ValidationStates | The HasError attached property is true has the control does not have focus. |
TreeView ControlTemplate Example
The following example shows how to define a ControlTemplate for the TreeView control and its associated types.
Wpf Treeview Example
The preceding example uses one or more of the following resources.
Wpf Treeview Tutorial
For the complete sample, see Styling with ControlTemplates Sample.