Linking to an element in a UserControl
If you want to bind to an external control where you are using this custom control, declare a DependencyProperty
UserControl in your code and then bind G1 to this property. And bind the external control property to UserControl DependencyProperty
. This is similar to level 2 indirection.
source to share
If you mean outside the outer control and not as the content of the control, you can use ElementName
in Binding like so:
{Binding ElementName=G1, Path=ActualWidth}
If you mean an external control in another Xaml file, you can try using the Path property if your control is in the scope of another control:
{Binding ElementName=ParentControl, Path=G1.ActualWidth}
However, I would advise against this design, because one day you can change the name of the G1 and you will never know about any bindings that might break.
source to share