Rocko Bonaparte
Topic Author
Posts: 18
Joined: 13 Oct 2020, 08:32

Your preferred RelayCommand implementation

24 Dec 2020, 09:29

I'm still new to WPF and have been surprised to hear about the peculiar culture of it. In this case, I'm talking about the various ways people implement some things for it that are surprisingly not included in a default way like RelayCommand.

I was dabbling in Visual Studio with a project first, and I started using this RelayCommand: ... nd-in-wpf/

I have a lot of buttons and use that RelayCommand to bind commands to run when the buttons are pressed.

The problem with integrating with NoesisGUI comes down to CommandManager in the CanExecuteChanged handler:
        public event System.EventHandler CanExecuteChanged
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
This isn't found when building in Unity. What I gathered from other posts on here is that Noesis has something like CommandManager but doesn't expose it. For what it's worth, I can stub out the handlers and just have them do nothing. It seems to not harm my project, but I suspect it harms some optimizations. Other people have their own RelayCommands they rely on so I just figured I'd ask what you are using instead.

User avatar
Site Admin
Posts: 2056
Joined: 22 Dec 2011, 19:20

Re: Your preferred RelayCommand implementation

24 Dec 2020, 11:45

Hi, in our samples we use this implementation: ... Command.cs
Regarding CanExecuteChanged our commands code doesn't rely on CommandManager to update UI so there was no need to expose the class to C#. You can just leave it as a simple event and raise it when CanExecute changes to notify the UI.

Who is online

Users browsing this forum: No registered users and 0 guests