c# - Value cannot be null CommandBinding custom command -


i've started wpf few days ago , have come problem dont understand.

i got following error:

value cannot 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 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 error occurs if use custom command not if use e.g. command="applicationcommands.new" , how can fix error?

the code part of this tutorial.

maybe need set customcommands not static,

and let mainwindow's datacontext customcommands

 public class customcommands  {         public static readonly routeduicommand exit = new routeduicommand                 (                         "beenden",                         "exit",                         typeof(customcommands),                         new inputgesturecollection()                         {                             new keygesture(key.f4, modifierkeys.alt)                         }                 );  }  public partial class mainwindow : window {     public  customcommands cm;     public mainwindow()     {         cm = new  customcommands();         this.datacontext = cm;         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();     }  } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -