Relay / ICommand vs DelegateCommand - Differences

As far as I can tell, the code below can be changed using the Relay / ICommand Command command to delegate and still bind the commands the same way! If I am wrong, what are the differences and their use.

private DelegateCommand something; public DelegateCommand Something 

Here is the full implementation

 private RelayCommand something; public ICommand Something { get { if (something == null) something = new RelayCommand(SomethingMethod, CanSomething); return something; } } private bool CanSomething(object parameter) { //just for readability return true return true; } private void SomethingMethod(object parameter) { using (DatabaseContext context = new DatabaseContext()) { try { } catch(Exception ex) { throw new ApplicationException(string.Format("Something {0} to {1}", file, directory), ex); } } } 
+4
source share
1 answer

In the structure itself, there is no DelegateCommand and RelayCommand . They are provided by third-party libraries.

Both are ICommand implementations that work by accepting a delegate and using this to provide an ICommand implementation. Thus, both classes have the same intentions and work basically the same.

As for the differences - there may be some subtle differences, depending on which structure you are using. For example, Prism DelegateCommand<T> also has the concept of IActiveAware , which is used to build composite teams.

+17
source

Source: https://habr.com/ru/post/1485081/


All Articles