gpt4 book ai didi

binding - MvvmCross Android 对话框以编程方式绑定(bind)

转载 作者:行者123 更新时间:2023-12-02 14:14:08 25 4
gpt4 key购买 nike

我想在我的 MvvmCross 项目中使用 Android.Dialog (Cross.UI)。我的第一个方法是使用 AutoViews。由于此功能还相当年轻,因此替代方案是在 touch 和 Droid 平台上实现对话框。

现在我只是为 Droid 执行此操作,我需要以编程方式将 ViewModel 的属性绑定(bind)到 Dialog 的元素。

我的 View 和ViewModel代码如下:

查看

    public class DialogConfigurationView : MvxBindingDialogActivityView<DialogConfigurationViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
DroidResources.Initialise(typeof(Resource.Layout));

Root = new RootElement()
{
new Section("Private Configuration")
{
new EntryElement("Name:"),
new EntryElement("Description:"),
new BooleanElement("Active?")
}
};
}
}

View 模型

    public class DialogConfigurationViewModel : MvxViewModel
{
public ConfigurationSet Configuration
{
get { return _configuration; }
set
{
if (_configuration != value)
{
_configuration = value;
RaisePropertyChanged(() => Configuration);
}
}
}
private ConfigurationSet _configuration;
}

我的目标是将 EntryElement("Name:") 与属性 ViewModel.Configuration.Name 进行双向绑定(bind)。

有人可以帮我解决这个问题吗?这可以吗?

最佳答案

我不知道是否有任何不使用自动 View 的 monodroid.dialog mvvmcross 样本!

但是......绑定(bind)的基本语法应该与 MonoTouch.Dialog 相同 - 例如像这样:

                            new Section("Contact Info")
{
new StringElement("ID", ViewModel.Customer.ID ?? string.Empty),
new EntryElement("Name", "Name").Bind(this, "{'Value':{'Path':'Customer.Name'}}"),
new EntryElement("Website", "Website").Bind(this, "{'Value':{'Path':'Customer.Website'}}"),
new EntryElement("Primary Phone", "Phone").Bind(this, "{'Value':{'Path':'Customer.PrimaryPhone'}}"),
},
new Section("Primary Address")
{
new EntryElement("Address").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Street1'}}"),
new EntryElement("Address2").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Street2'}}"),
new EntryElement("City").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.City'}}"),
new EntryElement("State").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.State'}}"),
new EntryElement("Zip").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Zip'}}"),
},

来自 https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/BaseCustomerEditView.cs

<小时/>

请注意,在 MonoTouch 和 MonoDroid 的 MvvmCross 绑定(bind)中,文本编辑框等内容的默认绑定(bind)通常默认为 TwoWay

<小时/>

如果您确实运行了一个示例,那么请随时将其发布到要点或存储库 - 或发布有关它的博客 - 看起来我们可以使用一些示例来工作!

关于binding - MvvmCross Android 对话框以编程方式绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14384229/

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