【发布时间】:2020-03-12 04:37:28
【问题描述】:
问题已解决,创建此问题是因为此特定情况不在线。
澄清一下,根据https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-bindings-to-mvvmMicrosoft 的 Xamarin MVVM 文档,一切都已正确实施
BindingContext、OnAppearing、INotifyPropertyChanged 等都是完美的。
情况
- 我有一个带有客户端对象列表的选择器。
- 我有 4 个条目,每个条目都有两种方式绑定到 Location 对象中的属性。例如。
<Entry x:Name="StreetName_Entry"
Text="{Binding Location.StreetName, Mode=TwoWay}"/>
- 当在客户端选择器中选择客户端时,程序需要获取与客户端对象关联的地址对象,并将该地址对象中的每个属性应用到位置对象(地址和位置在结构上相同) 例如
public async void SetLocationAsClientAddress()
{
Client client = Client;
Address clientsAddress;
if (client != null)
{
clientsAddress = await Database.GetAddressFor(client);
// Location is a property in the ViewModel, as well as an object type
Location.StreetNumber = clientsAddress.StreetNumber;
Location.StreetName = clientsAddress.StreetName;
Location.Suburb = clientsAddress.Suburb;
Location.Postcode = clientsAddress.Postcode;
}
}
- 因为位置对象属性现在填充了数据,这些应该立即显示在 4 Entry.text 中,因为有两种方式绑定。他们没有。
【问题讨论】:
标签: c# mvvm xamarin.forms data-binding