There is an Action base class denoting an action:
public class BaseAction { public string Name {get;set;} } And there is a class-successor ExpanderAction , which denotes a series of such actions:
public class ExpanderAction : BaseAction { public List<BaseAction> Actions {get;set;} = new List<BaseAction>(); } There is also a collection of items that is bound to an ItemsControl :
public ObservableCollection<BaseAction> Actions {get;set;} = new ObservableCollection<BaseAction>(); Elements of the collection can be represented by 2 types: a button or another collection with elements. The desired template is selected via ItemTemplateSelector .
<DataTemplate x:Key="BaseActionTemplate" DataType="{x:Type actions:BaseAction}"> <Button Content="{Binding Name}" /> </DataTemplate> <DataTemplate x:Key="ExpanderActionTemplate" DataType="{x:Type actions:ExpanderAction}"> <ItemsControl ItemsSource="{Binding Actions}" /> </DataTemplate> The problem is that inside the ItemsControl , which lies in the ExpanderActionTemplate template, the elements need to be displayed also by the 2nd same templates. It turns out something like a recursion.
Tell me how to indicate inside the ExpanderActionTemplate that the data in ItemsControl should be displayed by its own template?
Update
I do this, but an error occurs on the line Second="{StaticResource Second}" . This is due to the fact that the selector is declared earlier than the Second data template.
<Window.Resources> <DataTemplate x:Key="First"> <Button Content="{Binding Name}" /> </DataTemplate> <local:Selector x:Key="Selector" First="{StaticResource First}" Second="{StaticResource Second}"/> <DataTemplate x:Key="Second"> <ItemsControl ItemTemplateSelector="{StaticResource Selector}" ItemsSource="{Binding Path=ChildActions}"/> </DataTemplate> </Window.Resources> <StackPanel> <ItemsControl ItemsSource="{Binding Actions}" ItemTemplateSelector="{StaticResource Selector}" /> </StackPanel>
HierarchicalDataTemplate. - VladDHierarchicalDataTemplateyou can normally use only cTreeView. If to use withItemsControl, then child elements are not displayed. - trydexItemTemplateSelector? Give more code. - VladDItemTemplateSelectorinside theExpanderActionTemplateinItemsControl? - VladD