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}"/>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You want the
MyAttachedProp.Valueto have theWindowobject 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
RelativeSourceobject (with theModeset toSelf)…instead it points to the Static one already created in theRelativeSourceclass….(this is a VERY minor and premature optimization).Most people use example 3 as it’s less to type and clearer to read.