Is it possible to template a template in WPF XAML? -


Is it possible to use templates inside templates?

For example, I have the following two templates:

  & lt; HierarchicalDataTemplate x: Key = "RecursiveTemplate" ItemsSource = "{Binding Kids}" & gt; & Lt; StackPanel margin = "1" Orientation = "horizontal" & gt; & Lt; Ellipse Fill = "DarkGreen" width = "14" height = "14" /> & Lt; TextBlock MouseDown = "OnTargetUpdated" visibility = "{Binding Editing, Converter = {Static Resource Visibility Internet}}" Margin = "5" text = "{Binding Name}" /> & Lt; TextBox PreviewKeyDown = "OnTreeKeyDown" visibility = "{binding edit, converter = {static resource visibility converter}}" margin = "2" text = "{binding name}" /> & Lt; / StackPanel & gt; & Lt; / HierarchicalDataTemplate & gt; & Lt; Hierarchical data template x: key = "containermetlet" item source = "{binding child}" & gt; & Lt; StackPanel margin = "1" Orientation = "horizontal" & gt; & Lt; Ellipse Fill = "Darkballu" width = "14" height = "14" /> & Lt; TextBlock MouseDown = "OnTargetUpdated" visibility = "{Binding Editing, Converter = {Static Resource Visibility Internet}}" Margin = "5" text = "{Binding Name}" /> & Lt; TextBox PreviewKeyDown = "OnTreeKeyDown" visibility = "{binding edit, converter = {static resource visibility converter}}" margin = "2" text = "{binding name}" /> & Lt; / StackPanel & gt; & Lt; / HierarchicalDataTemplate & gt;  

There is a section of the same XAML:

  & lt; TextBlock MouseDown = "OnTargetUpdated" visibility = "{binding editing, converter = {static resource visibility internet}}" margin = "5" text = "{binding name}" /> & Lt; TextBox PreviewKeyDown = "OnTreeKeyDown" visibility = "{binding edit, converter = {static resource visibility converter}}" margin = "2" text = "{binding name}" />  

Is it possible to transfer it to the resource and instead of repeating its name should it go by name?

The answer can be "almost"

  & lt; Style x: key = "textBlockStyle" TargetType = "TextBlock" & gt; & Lt; Setter property = "visibility" value = "{binding edit, converter = {static resource visibility internet}}" /> & Lt; Setter property = "margin" value = "4" /> & Lt; Setter property = "text" value = "{binding name}" /> & Lt; EventSetter Event = "MouseDown" Handler = "Owner Maused Down" /> & Lt; / Style & gt; & Lt; Style x: key = "text box style" target type = "text box" & gt; & Lt; Setter property = "visibility" value = "{binding edit, converter = {static resource visibility converter}}" /> & lt; Setter property = "margin" value = "1" /> & Lt; Setter Property = "Text" Value = "{Compulsive Name, Notification Update = True}" /> & Lt; EventSetter Event = "Preview Kidadown" Handler = "OntreeKidown" /> & Lt; / Style & gt;  

Then templates

  & lt; Hierarchical data template x: key = "recursive template" items source = "{binding child}" & gt; & Lt; StackPanel margin = "1" Orientation = "horizontal" & gt; & Lt; Ellipse Fill = "DarkGreen" width = "14" height = "14" /> & Lt; TextBlock Style = "{StaticResource textBlockStyle}" /> & Lt; Textbox source update = "onsized update" style = "{static resource text box style}" /> & Lt; / StackPanel & gt; & Lt; / HierarchicalDataTemplate & gt; However, note that you can not keep SourceUpdated in a style, because it is not covered by EventSetter 


Comments