【发布时间】:2017-08-05 02:34:42
【问题描述】:
我正在尝试通过创建一个对象并绑定该对象来使用 MvvmHelpers 绑定一些数据。
https://github.com/jamesmontemagno/mvvm-helpers
在我的模型中,我有几个数据要绑定,所以我只是制作了一个我正在处理的快速模板。
如果我将 NameModel 中的内容移动到 NameViewModel,它确实可以工作,但是我正在尝试分离我的数据。
型号:
public class NameModel : BaseViewModel
{
string name;
public string Name
{
get { return name; }
set { SetProperty(ref name, value); }
}
}
查看模型:
public class NameViewModel : BaseViewModel
{
NameModel nameModel;
public NameViewModel()
{
nameModel = new NameModel { name="Jon Doe" };
}
}
Page.xaml.cs
public partial class NamePage : ContentPage
{
public NamePage()
{
InitializeComponent();
BindingContext = new NameViewModel();
}
}
Page.xaml:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NameProj.NamePage">
<StackLayout
Orientation="Vertical" >
<Label
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent"
Text={Binding Name}/>
</StackLayout>
</ContentPage>
【问题讨论】:
标签: c# xamarin mvvm data-binding xamarin.forms