c# - WPF - Model method as Execute event for a command (NO RelayCommand or DelegateCommand) -


i want use method not in code behind command's executed event , canexecute.

i'm using routedcommand , not want use delegate command or relay command.

what got commands class:

public class commands {     static commands()     {         synccommand = new routeduicommand("sync", "synccommand", typeof(commands));         undocommand = new routeduicommand("undo", "undocommand", typeof(commands));     }      private static myhandler handler;     public static myhandler handler     {         set { handler = value; }         { return handler; }     }      private static routeduicommand synccommand;     public static routeduicommand synccommand     {                 { return synccommand; }     }      private static void synccanexecute(object sender, canexecuteroutedeventargs e)     {         e.canexecute = handler != null;     }      private static void syncexecute(object sender, executedroutedeventargs e)     {         handler.action();     }      private static routeduicommand undocommand;     public static routeduicommand undocommand     {       {  return undocommand; }     }      private static void undocanexecute(object sender, canexecuteroutedeventargs e)     {         e.canexecute = handler.werechangesmade();     }      private static void undoexecute(object sender, executedroutedeventargs e)     {         handler.undo();     } } 

and in viewmodel got icommand properties , buttons command property binds these properties.

i want use above methods methods i'll pass command binding. how do when they're not in code behind?

you need add commandbinding 1 of ui elements, routeduicommand needs tunnel , bubble somewhere handled. if else fails, mainwindow.

commandbindings.add(new commandbinding(commands.synccommand, commands.syncexecute, commands.synccanexecute)); 

syncexecute , synccanexecute need accessible binding made, private won't do.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -