Hello. I'm trying to use RoutedCommand and Command in a Menuitem. I have done following:
_commandNewProject = new RoutedCommand("NewProject", typeof(Project)); var binding = new CommandBinding(_commandNewProject, executedEventHandlerDoNewProject, canExecutedEventHandlerDoNewProject); CommandManager.RegisterClassCommandBinding(typeof(Project), binding);
And Xaml.
<Window x:Class="ListOfActiveEdges.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:ListOfActiveEdges" Title="MainWindow" Height="350" Width="525"><DockPanel Name="DockPanel1" VerticalAlignment="Stretch" IsEnabled="True"> <Menu DockPanel.Dock="Top" IsMainMenu="True" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto"><MenuItem Header="_File"><MenuItem Name="New" Header="_New" Command="my:Project.NewProject" CommandTarget="{Binding Source={x:Static my:Project.Instance}}"/></MenuItem></Menu><Grid DockPanel.Dock="Bottom"> <Image Name="ImageContainer"/></Grid></DockPanel> </Window>
Project.Instance is a static method which returns Project. And Project.Instance is called. But menuitem is inactive all time. Thanks.