I've just started with WPF a few days ago and have come to a problem I dont understand.
I got the following error:
Value cannot be null. Parametername: value
The error occurs here:
<Window.CommandBindings>
<CommandBinding Command="self:CustomCommands.Exit" Executed="ExitCommand_Executed" CanExecute="ExitCommand_CanExecute"/>
</Window.CommandBindings>
I've of course set namespace xmlns:self="clr-namespace:PrintMonitor"
in the xaml.
The code-behind:
namespace PrintMonitor
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ExitCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if(e != null)
e.CanExecute = true;
}
private void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Application.Current.Shutdown();
}
}
public static class CustomCommands
{
public static readonly RoutedUICommand Exit = new RoutedUICommand
(
"Beenden",
"Exit",
typeof(CustomCommands),
new InputGestureCollection()
{
new KeyGesture(Key.F4, ModifierKeys.Alt)
}
);
}
}
So why does this error occurs if I use a custom command but not if i use e.g. Command="ApplicationCommands.New"
and how can I fix this error?
The Code is part of this tutorial.
Click on the button "Enable Project Code" Just under the designer window
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With