It depends on what you want. I will try to give a complete answer. One way to guarantee better success with this syntax is to use the VS2010 XAML Binding Builder , this is how I put together the syntax you are about to see.
If you want the UserControl element to display your IPAddress dependency property (which looks like it is defined correctly for me), use this syntax in the UserControl markup body:
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type my:GridControl}, AncestorLevel=1}, Path=IPAddress}" />
Most XAML binding examples use this syntax, rather than the more verbose hierarchical XML:
<TextBlock> <TextBlock.Text> <Binding Path="IPAddress"> <Binding.RelativeSource> <RelativeSource Mode="FindAncestor" AncestorType="{x:Type my:GridControl}" AncestorLevel="1" /> </Binding.RelativeSource> </Binding> </TextBlock.Text> </TextBlock>
... but both kinds of syntax give the same results. Note that AncestorType is the class name of your UserControl, not x:Name , which you specify when using UserControl in a different markup.
Suppose you have a user interface element in the markup outside your UserControl, and you want to access your DependencyProperty for this other control . The markup looks something like this:
<my:GridControl x:Name="GridControl1" IPAddress="192.168.1.1" /> <TextBox Text="{Binding ElementName=GridControl1, Path=IPAddress}"/>
Or, alternatively, this:
<TextBox> <TextBox.Text> <Binding ElementName="GridControl1" Path="IPAddress"/> </TextBox.Text> </TextBox>
Note that this time you use the x:Name GridControl property, not the class name, and refer to it as an ElementName , not an Ancestor. In both cases, however, Path is the declared name of the DependencyProperty you define.