I have silverlight usercontrol. This contains Service Entity object. see below
public partial class MainPage : UserControl
{
public ServiceRef.tPage CurrentPage { get; set; }
...
}
I need to bind CurrentPage.Title to TextBox
My xaml is here
<TextBox Text="{Binding Path=CurrentPage.Title, RelativeSource={RelativeSource self}}"></TextBox>
But it is not work.
How to do it?
In order for that to work, you’ll have to implement
INotifyPropertyChangedon your class and raise thePropertyChangedevent forCurrentPagewhen it’s set (this also means you won’t be able to use auto properties; you’ll have to use your own private instance backing variable and code theget { }andset { }yourself).What’s happening is the control is binding to the value before you’ve set
CurrentPage. Because you aren’t notifying anyone that the property has changed, it does not know to refresh the bound data. ImplementingINotifyPropertyChangedwill fix this.Or you could just manually set the
Textproperty yourself in the setter.