I am trying to bind data in C # code, not in XAML. The XAML binding created in Expression Blend 2 with my CLR object works fine. My C # implementation is only updated when the application starts, after which subsequent changes to the CLR do not update the contents of my label.
Here's the working XAML binding. First, an ObjectDataProvider is created in my Window.Resources.
<ObjectDataProvider x:Key="PhoneServiceDS" ObjectType="{x:Type kudu:PhoneService}" d:IsDataSource="True"/>
And binding the contents of the label:
<Label x:Name="DisplayName" Content="{Binding Path=MyAccountService.Accounts[0].DisplayName, Mode=OneWay, Source={StaticResource PhoneServiceDS}}"/>
It works great. But we want this to be configured in C # so that we can independently modify the XAML (i.e. new skins). My one-time working C # looks like this:
Binding displayNameBinding = new Binding(); displayNameBinding.Source = PhoneService.MyAccountService.Accounts[0].DisplayName; displayNameBinding.Mode = BindingMode.OneWay; this.DisplayName.SetBinding(Label.ContentProperty, displayNameBinding);
This is inside my MainWindow after InitializeComponent ();
Any insight into why this only works on startup?
source share