gpt4 book ai didi

c# - 使用 Mvvm Helpers 进行数据绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 11:03:31 24 4
gpt4 key购买 nike

我试图通过创建一个对象并绑定(bind)该对象来使用 MvvmHelpers 绑定(bind)一些数据。

https://github.com/jamesmontemagno/mvvm-helpers

在我的模型中,我有几个数据要绑定(bind),所以我只是制作了一个我正在处理的快速模板。

如果我将 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" };
}
}

页面.xaml.cs
public partial class NamePage : ContentPage
{
public NamePage()
{
InitializeComponent();
BindingContext = new NameViewModel();
}
}

页面.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>

最佳答案

您是否尝试将其更改为 nameModel.Name ?

<Label
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent"
Text="{Binding nameModel.Name}"/>

希望能帮助到你!

关于c# - 使用 Mvvm Helpers 进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42791387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com