Bonjour,

J'ai créé un custom TreeView puis je lui ai associé un menu contextuel. J'aimerais associer une custom commande sur l'élément du menu.
J'ai défini ma commande dans mon custom TreeView:
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static RoutedCommand MyCommand;
 
static MyTreeView()
{ 
    MyCommand = new RoutedCommand("MyCommand", typeof(MyTreeView));
 
    CommandBinding binding = new CommandBinding();
    binding.Command = MyCommand;
    binding.Executed += OnMyCommandExecuted;
 
    CommandManager.RegisterClassCommandBinding(typeof(MyTreeView), binding);
}
 
static private void OnMyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
 
}

Voici le menu contextuel:
Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<ContextMenu x:Key="MyContextMenu" StaysOpen="true">
        <MenuItem Header="MyMenuItem "  Command="{Binding MyCommand }" />      
</ContextMenu>

Malheureusement, la commande n'est jamais executée...

Merci.