I need to do some visual effects on the control after a particular ICommand was executed. For example, my Custom control exposes AAACommand and BBBCommand properties.
<myControl AAACommand={Binding ACommand}
BBBCommand={Binding BCommand} />
where ACommand and BCommand are Commands on ViewModel. How do I know when AAACommand was executed, so I can do some UI stuff in my UserControl? there is no Executed event for ICommand to subscribe to.
Edit: AAACommand is defined like this on my user control:
public static readonly DependencyProperty AAACommandProperty =
DependencyProperty.Register("AddCommand", typeof(RelayCommand), typeof(MyCustomControl), null);
public static readonly DependencyProperty AAACommandParameterProperty =
DependencyProperty.Register("AAACommandParameter", typeof(object), typeof(MyCustomControl), null);
public RelayCommand AAACommand
{
get { return (RelayCommand)GetValue(AAACommandProperty); }
set { SetValue(AAACommandProperty, value); }
}
public object AAACommandParameter
{
get { return (object)GetValue(AAACommandParameterProperty); }
set { SetValue(AAACommandParameterProperty, value); }
}
So, there is no problem in invoking ACommand on ViewModel, this works without problem. The problem is how will my user control know when AAACommand will execute ACommand, so it can do something with its UI.
You want to update the usercontrol based upon a response returned from the view model and the command executed? I asked a question similar in nature where I wanted to pass as string value from one user control to another user control. I accomplished this using INotifyProperty Changed event. You can read the original question and solution here
Update to comment:
Base on your comment it seems like one of two things could happen. If you don’t need the VM to respond then the update could be triggered by elements in the view. You could do this using Binding ElementNameProperty. This in essence allows you to trigger/change a property based upon the action of another element. (typing text in one field displays the value in another control) Here is the msdn description and example .
If you need it to be invoked based upon the return (i.e. success or failure) then the ViewModel will need to have a property (like a bool) that is bound two-way to the property of the element in the ui.
You may need to create a converter (inheriting IValueConverter ) to handle the binding but INotifyProp Change would be used to marshal the update between the controls or the bound elements within them.
Here is a quick example:
within my xaml I added a user control that I did not want to be visible within the UI until another button within a secondary usercontrol was clicked. To handle this I setup binding on the Visibility property
Within the viewmodel I had the following property and code
property in VM (note I use SimpleMVVM framework which has Inotify included in the base object so my notify prop event may look a bit different from yours)
Then the method within the VM that updated this property
And finally the converter class which would convert the return value to the correct property value for the element