Please excuse me if this is a stupid question - I have read a dozen articles on the WPF command framework and I'm more confused than ever.
I understand that I can use the built-in commands to implement (for example) a toolbar that will apply the standard cut / copy / paste functions for any focused text field:
<ToolBar> <Button Command="{x:Static ApplicationCommands.Cut}">Cut</Button> <Button Command="{x:Static ApplicationCommands.Copy}">Copy</Button> <Button Command="{x:Static ApplicationCommands.Paste}">Paste</Button> </ToolBar>
But I want to expand this template so that you can use one toolbar to invoke similar (but not identical) operations for a number of different controls. For example, I can create a custom control that comes from a ListBox that also supports cut, copy, and paste operations. Although the execution of the copy operation in the ListBox will be encoded differently compared to the execution of the TextBox, it will still be called from the same button on the toolbar.
So my questions are:
[1] What needs to be implemented in a user control so that it can be commanded, as in the above example? In particular, it should be searchable from the toolbar when focusing.
[2] What markup is required on the toolbar so that one button calls up different commands depending on the type of focused control?
Thanks so much for any advice you can offer.
Tim
source share