且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#中的数据绑定不更新WPF

更新时间:2023-10-02 18:24:10

您的C#版本不匹配的XAML版本。它应该可以写你的标记的code版本,虽然我不熟悉的ObjectDataProvider。

Your C# version does not match the XAML version. It should be possible to write a code version of your markup, though I am not familiar with ObjectDataProvider.

尝试是这样的:

Binding displayNameBinding = new Binding( "MyAccountService.Accounts[0].DisplayName" );
displayNameBinding.Source = new ObjectDataProvider { ObjectType = typeof(PhoneService), IsDataSource = true };
displayNameBinding.Mode = BindingMode.OneWay;
this.DisplayName.SetBinding(Label.ContentProperty, displayNameBinding);