Hello,
I want to put all my events in one class file and call them in a main window
following is my code in mainwindow.xaml file
<Window x:Class="WPF123.MainWindow"
xmlns:Local="clr-namespace:WPF123">
<Window.CommandBindings >
<CommandBinding Command="Local:MyCommands.Print" Executed="PrintCommandHandler" CanExecute="CommandBinding_CanExecute" />
</Window.CommandBindings>
...
<Button SmallImageSource="Images\Print.png" ToolTipTitle="Print" Command="Local:MyCommands.Print" />
</Window>
public MainWindow()
{
InitializeComponent();
MyCommands.BindCommandsToWindow(this);
}
And I created a Class called MyCommands followings is the code
public static class MyCommands
{
private static RoutedUICommand Print;
static MyCommands()
{
Print = new RoutedUICommand("Print","Print",typeof(MyCommands));
}
public static void BindCommandsToWindow(Window window)
{
window.CommandBindings.Add(new CommandBinding(Print,PrintCommandHandler));
}
public static void PrintCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
PrintDialog prtdialog = new PrintDialog();
prtdialog.ShowDialog();
}
public static void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
}
What did I miss on button line it says I get error saying "type Local:Mycommands cannot be found"...