我无法将值从ViewModel绑定到View,可以看到值正在设置(ServiceList)
这里是Xaml
XAML:
<Label
Grid.Row="0"
FontFamily="{StaticResource BoldFont}"
FontSize="{StaticResource NormalFontSize}"
HorizontalOptions="StartAndExpand"
Text="{Binding Heading, Mode=TwoWay}"
TextColor="Black"
VerticalOptions="CenterAndExpand" />
PageViewModel:
private string _Heading;
public string Heading
{
get { return _Heading; }
set { _Heading = value; SetProperty(ref _Heading, value); }
}
async void LoadData(Service service)
{
Dictionary<string, string> data = new Dictionary<string, string>();
if (App.Current.Properties.ContainsKey("user_id"))
data.Add("user_id", App.Current.Properties["user_id"].ToString());
data.Add("subcategory", service.id.ToString());
data.Add("city", "ABC");
UserResponse = await HomeService.GetServices(data);
if (UserResponse.status == 200)
{
Heading = "529 Interior Decorators in Las Vegas";
}
}
答案 0 :(得分:3)
这是因为SetProperty
仅在值实际更改时才提高PropertyChanged
。通过预先设置,可以防止这种情况,并且视图无法知道应该更新。
您要写:
public string Heading
{
get { return _Heading; }
set { SetProperty(ref _Heading, value); }
}
请注意缺少的_Heading = value;