So you need to tell the binding where the property lives. There's a couple of ways to do this (you can do it with a RelativeSource using FindAncestor) but the easiest way is to give the UserControl a "name" in the XAML and bind using element binding: UserControl ... x:Name="me" /> TheText" property - you needn't change any of your other code, although you'll probably want to implement INotifyPropertyChanged on your underlying MyClass object so that the binding knows when the property has changed.
So you need to tell the binding where the property lives. There's a couple of ways to do this (you can do it with a RelativeSource using FindAncestor) but the easiest way is to give the UserControl a "name" in the XAML and bind using element binding: Now your TextBox will reflect the value you've assigned (or bound) to your "SomeControl. TheText" property - you needn't change any of your other code, although you'll probably want to implement INotifyPropertyChanged on your underlying MyClass object so that the binding knows when the property has changed.
I'm setting the DataContext of the UserControl to 'this' in its constructor, therefore the Binding knows which property is meant. The value of the textbox is also bound correctly to the UserControl's property, but it seems that the databinding gets lost in my Windows. – Oliver Hanappi Jul 28 '09 at 5:51 Ah right - yeah, I've seen people try that.
I think that's what confuses the bindings up at the Window level. Doing it with an Element Binding eliminates the need for that. – Matt Hamilton Jul 28 '09 at 6:11 Okay, I solved it now.
The problem was that I need to set the binding mode to TwoWay in my window. Thank you for your help! – Oliver Hanappi Jul 28 '09 at 6:59.
Matt has provided a solution to your problem. Here is a little more explanation and a hint to stop this problem in future. As SomeControl.
DataContext is set in the SomeControl constructor, the window's binding TheText="{Binding Path=MyStringProp}" has a Source of type SomeControl, not MyClass as you intended. Any bindings that fail at runtime cause debug messages to be logged to the output panel of Visual Studio. In this case, you would have seen that no such property 'MyStringProp' exists on object of type 'SomeControl', which should have raised your suspicions.
I think everyone finds WPF data binding takes some time to learn and especially to debug, but persevere. Data binding in WPF is really fantastic, and I still get a kick out of knowing how easily it makes the data on my UIs stay up to date.
Thank you for your advice;) – Oliver Hanappi Jul 28 '09 at 7:11.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.