0

Is there a best practice for how to enable (CanExecute) a button in an other userControl?

A simple scenario is as follow. When selecting one row in a datagrid in UserControl_1 a button should be enabled in UserControl_2 and also provide the selected row to UserControl_2's viewModel.

When the user then push the button in UserControl_2 it will be executed with the data from the selected row from UserControl_1.

Thanks from a Catel newbie.

Greg
  • 25
  • 3

2 Answers2

0

If you are using WPF (assuming you are), the CanExecute will be triggered by the WPF system (CommandManager to be precise). Catel should automatically requery the commands when a property changes.

If the logic (or at least the data) for the CanExecute should be shared among several user controls (and I am talking about the view models for the several user controls), I recommend to create a service which is registered in the ServiceLocator. In the CanExecute of the commands you can query the same data (the service) and return true or false according to the logic you want to implement.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32
-1

You may take a look at this post. And you 'll have a good idea about your problem. I don't post the code here since it is an answer of someone else. Please refer the link.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/198c4a4b-b4c2-4dfc-b99b-afb2a11eb4c3/call-button-even-from-user-control-to-another-user-control

tarzanbappa
  • 4,930
  • 22
  • 75
  • 117