If you give the root element of UserControl a name, then you can access it using ElementName:
<UserControl x:Class="muc" Name="rootElement"> <Label Foreground="#FF7800" FontSize="20" FontWeight="Bold"> <Label.Content> <Binding ElementName="rootElement" Path="TestName" /> </Label.Content> </Label> </UserControl>
You can also use markup extension syntax to make it a little shorter:
<UserControl x:Class="muc" Name="rootElement"> <Label Foreground="#FF7800" FontSize="20" FontWeight="Bold" Content="{Binding TestName, ElementName=rootElement}"/> </UserControl>
Also remember that your control will be created before its properties are set. You need to either implement INotifyPropertyChanged or have the TestName dependency property so that the binding is reevaluated after the property is set.
Quartermeister
source share