That happens because you set the DataContext
of the UserControl
to itself. So, when the binding is applied, it searches the UserName
property in the UserControl
(and the property doesn't exist).
You can bind to a property of the UserControl
by giving a name to the UserControl
and, use the ElementName
property of the Binding
, like the following:
<UserControl
...
x:Name="myControl"
...
>
...
<TextBox Text="{Binding Value, ElementName=myControl}"
BorderBrush="Green" />
...
</UserControl>
Don't forget to remove the this.DataContext = this;
line from the constructor of the UserControl
. :)