【发布时间】:2019-01-09 06:05:39
【问题描述】:
我将我的项目从 MVVM Cross 迁移到 Xamarin Forms,并且我试图让标签的绑定属性出现在我的 Web 服务中,但它目前无法正常工作,就像 MVVM 一样。 当我运行该应用程序时,它在日志上没有显示任何错误,但它也没有显示我的任何属性,当涉及到我绑定的属性时,它只是空白,比如“标题”。
这是我的 XAML(表单)。
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.Core.Pages.DeliveryPage">
<ContentPage.Content Title="General" Icon="">
<ScrollView Orientation="Vertical">
<StackLayout HorizontalOptions="FillAndExpand">
<Label FontSize="Large" Text="GENERAL"/>
<Frame>
<Label x:Name="labelTitle" Text="{Binding Title}"/>
</Frame>
这是我的 CS(表单)
TestResponse test;
private string _title;
public string Title
{
get { return _title; }
set { _title = value; OnPropertyChanged(_title); }
}
然后我这样称呼它:
Title = "Title: " + "\n" + test.Title;
这是我使用 MVVM 的时候:
private string _title;
public string Title
{
get => _title;
set => SetProperty(ref _title, value);
}
【问题讨论】:
-
有什么问题?
-
@Arvindraja 那里,我已经更新了,我的错。
-
Title = "Title: " + "\n" + delivery.Title;这里是设置页面标题还是标签文字? -
标签文本,它将抓取我的网络服务上的文本
-
你的 ViewModel 是否实现了
INotifyPropertyChanged和set { _title = value; OnPropertyChanged(_title); }应该是set { _title = value; OnPropertyChanged(nameof(Title)); }
标签: c# xamarin.forms mvvmcross