Reputation: 3409
So I have a zoom-in-button placed in a menu bar, and several levels down there is a control I would like to have take the zoom in command and zoom in on the object being viewed and redraw.
As I understand from my reading, command normally bubble up with a preview event from the commandsource (in this case the button), and then tunnel back down to the command source, looking for a command binding that binds the command to the event handlers for the command. However, in my case, the control that I want to affect is levels down from the button.
Is it correct just having the binding be in a higher level control that gets hit, and then have that higher level control run the methods on the lower level function?
I thought it might look cleaner to just have the code set a command target onto the child descendant, but now i'm not sure if that is what command target actually does.
Can I just place command target like so:
CommandTarget="{Binding ElementName=wavegraphcanvas, Path=CommandTarget, Mode=OneWay}"
in the xaml and have it find the element in its children?*
I thought what would happen is that it would bubble up from the button and then tunnel down till it found the element name or something
Upvotes: 2
Views: 754
Reputation: 7037
The CommandTarget
is appropriate when you know what element is the target. In your case that seems to be true.
If you have multiple elements that can receive the command (for example, 3 text boxes getting the Paste
command) then it doesn't make sense to set the CommandTarget
. That's what the routing part of the RoutedCommand
does; attempt to find the appropriate element to apply the command,
Upvotes: 2