views:

1322

answers:

1

A better explanation, I hope:

  • I have a toolbar with 3 buttons on it, all three bound to a Command (including a CommandParameter)
  • this toolbar is used on several screens
  • the xaml of the toolbar is exactly the same over all those screens

I want to remove the toolbar instance and replace it with a user control that provides 3 commands, so I can keep the bindings in each screen. The plan is to later change the toolbar functionality, but the external programming interface (namely, 3 commands) is the same.

So:

  • I created a user control, and created 3 sets of dependency properties for each command (OneCommand, OneCommandParameter, OneCommandTarget) so I can use these for the binding.
  • I moved the toolbar xaml inside the user control xaml.
  • I modified the bindings on the toolbar buttons to bind to the intristic user control properties
  • on each screen (or really, only the first for now) I replaced the original toolbar with the user control,binding the new properties to the correct commands.

The control shows, but the buttons don't work. That's about it.

--

Original explanation - not so clear:

I have a WPF user control encapsulating a number of buttons. Previously, the control was a Toolbar with a number of buttons on it, but since I need exact the same functionality on a number of screens, I refactored the toolbar into a custom control.

However, I'd like to keep the command bindings of the original buttons.

  • I created 3 sets of dependency properties (XCommand, XCommandParameter and XCommandTarget) on the usercontrol.
  • In the user control xaml I bind the "real" buttons to those properties (each button to each set of properties).
  • Where I use the usercontrol, I bind the new properties to the real command bindings.

In essence, I want to keep the ICommandSource functionality for each "command" that the user control exposes. However, this dual databinding scenario doesn't seem to work, or I'm doing something wrong. :)

Is there a better way to do this? All I need is to "bridge" the commands from outside the control to the inner buttons so the Execute and CanExecute functionality remains.

A: 

I solved this. There was a bug in my RelativeSource in the internal control bindings. It works fine as expected, now.

Inferis
It'd be more helpful if you told us *how* you solved it. SO questions are supposed to be reusable so the next person who has the same problem can use your answer. ;)
jalf