I'm trying to learn Command Binding but with my first code I have an error.I searched a lot for resolve my problem but I wasn't successful. This is my XML Code :
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
x:Class="Office.Windows.winMain"
xmlns:local = "clr-namespace:Office"
Closing="Window_Closing"
mc:Ignorable="d" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" WindowState="Maximized"
Title="Main Window" Height="459.593" Width="604.36">
<Window.CommandBindings>
<CommandBinding Command="local:CustomCommands.Exit" CanExecute="ExitCommand_CanExecute" Executed="ExitCommand_Executed" />
</Window.CommandBindings>
<Grid>
</Grid>
</Window>
And this is my code behind
public partial class winMain : Window
{
public winMain()
{
InitializeComponent();
}
public static class CustomCommands
{
public static readonly RoutedUICommand Exit = new RoutedUICommand
(
"Exit",
"Exit",
typeof(CustomCommands),
new InputGestureCollection()
{
new KeyGesture(Key.End, ModifierKeys.Control)
}
);
}
private void ExitCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void ExitCommand_Executed(object sender,ExecutedRoutedEventArgs e)
{
Application.Current.Shutdown();
}
}
}
But in this code I have the error The name "CustomCommands" does not exist in the namespace "clr-namespace:Office". And also I have to say my MainWindow is in Windows Folder in my project but I tried both namespace clr-namespace:Office and clr-namespace:Office.Windows. What's wrong with my code?