I just started with WPF a few days ago and came up with a problem that I don't understand.
I got the following error:
The value cannot be null. Parameter Name: Value
The error is here:
<Window.CommandBindings> <CommandBinding Command="self:CustomCommands.Exit" Executed="ExitCommand_Executed" CanExecute="ExitCommand_CanExecute"/> </Window.CommandBindings>
Of course, I set the xmlns:self="clr-namespace:PrintMonitor" .
Code:
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 this error occurs if I use a user command, but not if I use, for example. Command="ApplicationCommands.New" and how can I fix this error?
Code is part of this guide .
source share