Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. TreeView in ControlTemplate - Handling Item Expanded

TreeView in ControlTemplate - Handling Item Expanded

Scheduled Pinned Locked Moved WPF
wpfwcf
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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)
    {

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups