I am new to WPF and I have some problems getting the data binding to work as I want. I wrote a user control that contains a TextBox whose Text-Property I want to bind to a property of my UserControl, which I want to bind to something else again.
What am I missing?
Xaml
<TextBox Text="{Binding Path=TheText}" />
<WpfApplication1:SomeControl TheText="{Binding Path=MyStringProp}" />
FROM#
public partial class SomeControl : UserControl
{
public DependencyProperty TheTextProperty = DependencyProperty
.Register("TheText", typeof (string), typeof (SomeControl));
public string TheText
{
get
{
return (string)GetValue(TheTextProperty);
}
set
{
SetValue(TheTextProperty, value);
}
}
public SomeControl()
{
InitializeComponent();
DataContext = this;
}
}
public partial class Window1 : Window
{
private readonly MyClass _myClass;
public Window1()
{
InitializeComponent();
_myClass = new MyClass();
_myClass.MyStringProp = "Hallo Welt";
DataContext = _myClass;
}
}
public class MyClass
{
public string MyStringProp { get; set; }
}
Best regards
Oliver Hanappi
PS: I tried to implement the INotifyPropertyChanged interface in my user control, but that didn't help.
source
share