TreeView in ControlTemplate - Handling Item Expanded
WPF
1
Posts
1
Posters
2
Views
1
Watching
-
I am creating a Custom Control and in the control template I have a TreeView class in it.
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:MyControl}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <TreeView ItemsSource="{Binding TreeDataItems, RelativeSource={RelativeSource TemplatedParent}}"> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type local:TreeItem}" ItemsSource="{Binding Children}"> <TextBlock Text="{Binding Path=Caption}" /> </HierarchicalDataTemplate> </TreeView.Resources> <i:Interaction.Triggers> <i:EventTrigger EventName="TreeViewItem.Expanded"> <i:InvokeCommandAction Command="{Binding TreeItemExpandedCommand, RelativeSource={RelativeSource TemplatedParent}}" CommandParameter="{Binding}"> </i:InvokeCommandAction> </i:EventTrigger> </i:Interaction.Triggers> </TreeView> </Border> </ControlTemplate> </Setter.Value> </Setter>
</Style>
In the code behind I have
private ICommand _TreeItemExpandedCommand;
public ICommand TreeItemExpandedCommand
{
get
{
if (_TreeItemExpandedCommand == null)
_TreeItemExpandedCommand = new RelayCommand(p => TreeItemExpandedExecuted(p));
return _TreeItemExpandedCommand;
}
}private void TreeItemExpandedExecuted(object args)
{
}When I expand a node nothing happens. There are no binding errors, and the Command's getter fires when it starts, but the TreeItemExpandedExecuted never fires.
I tried using the event itself:
...
and
private void TreeViewItem_Expanded(object sender, RoutedEventArgs e)
{