Ho appena iniziato con WPF alcuni giorni fa e ho riscontrato un problema che non capisco.Valore non può essere nullo CommandBinding comando personalizzato
ho ottenuto il seguente errore:
Value cannot be null. Parametername: value
L'errore si verifica qui:
<Window.CommandBindings>
<CommandBinding Command="self:CustomCommands.Exit" Executed="ExitCommand_Executed" CanExecute="ExitCommand_CanExecute"/>
</Window.CommandBindings>
ho naturalmente insieme namespace xmlns:self="clr-namespace:PrintMonitor"
in XAML.
Il 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)
}
);
}
}
Allora perché questo errore si verifica se si utilizza un comando personalizzato, ma non se uso per esempio Command="ApplicationCommands.New"
e come posso risolvere questo errore?
Il codice fa parte di this tutorial.
Quale versione di VS stai usando? Non sono in grado di riprodurre il tuo errore in base al tutorial e agli snippet forniti. – Geoffrey
Vs 2015 Enterprise V 14.0. Dovrei aggiungere che il progetto viene compilato ed eseguito ma l'errore persiste –
Ora ho creato un nuovo progetto e copiato 1: 1 e l'errore è scomparso ... bug intellisense credo !? –