WPF - How to force a Command to re-evaluate 'CanExecute' via its CommandBindings

前端 未结 6 1254
礼貌的吻别
礼貌的吻别 2020-11-29 17:47

I have a Menu where each MenuItem in the hierarchy has its Command property set to a RoutedCommand I\'ve defined. The as

6条回答
  •  抹茶落季
    2020-11-29 18:08

    I've implemented a solution to handle property dependency on commands, here the link https://stackoverflow.com/a/30394333/1716620

    thanks to that you'll end up having a command like this:

    this.SaveCommand = new MyDelegateCommand(this,
        //execute
        () => {
          Console.Write("EXECUTED");
        },
        //can execute
        () => {
          Console.Write("Checking Validity");
           return PropertyX!=null && PropertyY!=null && PropertyY.Length < 5;
        },
        //properties to watch
        (p) => new { p.PropertyX, p.PropertyY }
     );
    

提交回复
热议问题