In the normal WPF ContextMenu, if I add commands to MenuItems in a context menu, the keyboard shortcut is displayed, along with the command text, for something like "Open CTRL+O". But when I hook up a command to an actipro button in menu of a context menu, I don't get this "free" behavior. Is this something I now need to hook up manually, or is this supported in a different manner?
normal:
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3" Height="300" Width="300">
<StackPanel>
<TreeView x:Name="treeView">
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Open"/>
<MenuItem Command="ApplicationCommands.New" />
<MenuItem Command="ApplicationCommands.Close"/>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</StackPanel>
</Window>
actipro:
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:apc="clr-namespace:ActiproSoftware.Windows.Controls.Ribbon.Controls;assembly=ActiproSoftware.Ribbon.WPF30"
Title="Window3" Height="300" Width="300">
<StackPanel>
<TreeView x:Name="treeView">
<TreeView.ContextMenu>
<apc:ContextMenu>
<apc:Menu>
<apc:Button Command="ApplicationCommands.Open" />
<apc:Button Command="ApplicationCommands.Close" />
<apc:Button Command="ApplicationCommands.New" />
</apc:Menu>
</apc:ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</StackPanel>
</Window>
same code for both:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window3.xaml
/// </summary>
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
treeView.Items.Add("1");
treeView.Items.Add("21");
treeView.Items.Add("31");
treeView.Items.Add("41");
treeView.Items.Add("51");
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Execute, CanExecute));
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, Execute, CanExecute));
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, Execute, CanExecute));
}
public void Execute(object sender, ExecutedRoutedEventArgs e)
{
}
public void CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
}
}
normal:
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3" Height="300" Width="300">
<StackPanel>
<TreeView x:Name="treeView">
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Open"/>
<MenuItem Command="ApplicationCommands.New" />
<MenuItem Command="ApplicationCommands.Close"/>
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</StackPanel>
</Window>
actipro:
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:apc="clr-namespace:ActiproSoftware.Windows.Controls.Ribbon.Controls;assembly=ActiproSoftware.Ribbon.WPF30"
Title="Window3" Height="300" Width="300">
<StackPanel>
<TreeView x:Name="treeView">
<TreeView.ContextMenu>
<apc:ContextMenu>
<apc:Menu>
<apc:Button Command="ApplicationCommands.Open" />
<apc:Button Command="ApplicationCommands.Close" />
<apc:Button Command="ApplicationCommands.New" />
</apc:Menu>
</apc:ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</StackPanel>
</Window>
same code for both:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window3.xaml
/// </summary>
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
treeView.Items.Add("1");
treeView.Items.Add("21");
treeView.Items.Add("31");
treeView.Items.Add("41");
treeView.Items.Add("51");
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Execute, CanExecute));
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, Execute, CanExecute));
treeView.ContextMenu.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, Execute, CanExecute));
}
public void Execute(object sender, ExecutedRoutedEventArgs e)
{
}
public void CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
}
}