I bet this has been answered many times over, but...
For a simple situation where a button on a UserControl has its command property set to something like Find (ApplicationCommands.Find) how would the ViewModel handle that command? I usually see command handlers wired up with a CommandBinding that gets added to a CommandBindings collection on a UIElement, but my ViewModel doesn't derive from UIElement (should it?). The commands themselves don't expose events to notify when they've been executed, so where should I wire up to get that information?
EDIT: I'd like to use stock WPF to solve the problem if possible. I know there are many available frameworks for this sort of thing but would like to keep the code simple.
EDIT2: Including some sample code.
<UserControl>
<UserControl.DataContext>
<local:MyViewModel/>
</UserControl.DataContext>
<Button Command="Find"/>
</UserControl>
Where:
class MyViewModel
{
// Handle commands from the view here.
}
I could add a CommandBinding to the UserControl which would handle Executed, then call a hypothetical Find method in MyViewModel which does the actual work, but that's extra and unnecessary code. I'd prefer if the ViewModel itself handled the Find command. One possible solution would be to have MyViewModel derive from UIElement however that seems counter intuitive.