0

I have written a simple Window which contains a custom UserControl named A and two RadioButtons, named B1,B2. The custom UserControl A contains an InkCanvas named C and some other controls. Now I would like to MultiBinding the InkCanvas.EditingMode Property to the status of the two RadioButtons, saying when both the two buttons checked, the InkCanvas.EditingMode set to InkCanvasEditingMode.Ink, otherwise InkCanvasEditingMode.None.

I know that, in normal case, the following code can make it work:

<InkCanvas.EditingMode>
     <MultiBinding Converter="{StaticResource editmodeconv}">
           <Binding ElementName="B1" Path="IsChecked" Mode="TwoWay"/>
            <Binding ElementName="B2" Path="IsChecked" Mode="TwoWay"/>
      </MultiBinding>
</InkCanvas.EditingMode>

However, since the InkCanvas C has been contained by the custom UserControl A, it has no longer been exposed the two buttons B1 and B2. So, how to implement it?

C. Wang
  • 2,516
  • 5
  • 29
  • 46

2 Answers2

0

if it's possible you could try to send the radiobuttons to the usercontrols constructor. That way you'll have a reference to the buttons and therefore can check whether it's this or that :)

Or like wpf offers, you can look up the parent hierarchy and find the control holding the buttons. not sure the last option is what you wanna do in this case. I myself are still pretty new to wpf :)

I usually go with the first solution, but i'll bet if you wait, someone will come up with some databinding like you have tried yourself :)

EDIT:

found this post. They give you some great examples on what you could do in your case. http://social.msdn.microsoft.com/Forums/vstudio/en-US/ef295bd0-dafc-47ab-9453-25ad2a4dde30/binding-usercontrol-elements-properties?forum=wpf

Max Mazur
  • 1,188
  • 1
  • 13
  • 22
0

That's because you're not supposed to. The whole point of a control is to encapsulate the presentation of some kind of data.

Instead of trying to reach into the internals of the control, expose the DATA that your control wraps as dependency properties on the control. That way the control is free to present the data as radio buttons, or as something completely different, and the rest of the app will continue to work.

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103