WPF Binding to local variable
2011-11-14
Sample 1:
public string MyText {get;set;}
the binding is
{Binding MyText , RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}
Or
<Window Name="MyWindow" ...
<TextBlock Text="{Binding Text, ElementName=MyWindow}"/>
Sample 2:
<Window DataContext={Binding RelativeSource={RelativeSource Self}}>
then the binding is
{Binding Text}