I'm looking to see if you can bind the current instance of a usercontrol or window to an attached property defined in its xaml, eg:
<Window MyAttachedProp.Value="{Binding Self}"/>
You want the MyAttachedProp.Value
to have the Window
object reference?
You can use any of these methods:
{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}
give your Window an x:Name="XXXXX"...and then use {Binding ElementName=XXXXX}
to find it.
{Binding RelativeSource={RelativeSource Self}}
{Binding RelativeSource={x:Static RelativeSource.Self}}
With example 4, it avoids the creation of a new RelativeSource
object (with the Mode
set to Self
)...instead it points to the Static one already created in the RelativeSource
class....(this is a VERY minor and premature optimization).
Most people use example 3 as it's less to type and clearer to read.
{Binding RelativeSource={RelativeSource Self}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With