如何使用mvvmcross双向绑定到UITextView控件? [英] How do I do two-way binding to a UITextView control using mvvmcross?
问题描述
我有一个使用XCode(它是XIB)创建的简单视图.它由两个UITextView控件和一个UIButton组成.我已经将UITextView控件公开为Outlets,并为其指定了名称.一切在我的View.designer.cs文件中看起来都很好.
I have a simple view I created using XCode (it's a XIB). It consists of two UITextView controls and a UIButton. I've exposed the UITextView controls as Outlets and given them names. Everything looks good in my View.designer.cs file.
我正在使用以下语法创建绑定:
I'm creating my binding using this syntax:
this.AddBindings(
new Dictionary<object, string>()
{
{lastname, "{'Text':{'Path':'LastName','Mode':'TwoWay'}}"},
{uservin, "{'Text':{'Path':'CarVIN','Mode':'TwoWay'}}"}
});
当我从姓氏UITextView移到uservin UITextView时,我希望我的视图模型中的SETTER被调用,但没有被调用.当我单击按钮并检查ViewModel上两个文本属性的值时,它们都为空.
When I move from the lastname UITextView to the uservin UITextView I expect the SETTER in my viewmodel to get called, but it doesn't. When I click the button and check the value of the two text properties on my ViewModel, they are both null.
有人知道我做错了吗?我将在周二发布一个快速演示,所有其他平台都可以很好地运行,但是似乎无法克服这个问题.
Does anybody know what I've done wrong? I've got a quick demo due on Tuesday and have all other platforms working beautifully, but just can't seem to get past this issue.
干杯
/j
推荐答案
我认为问题是您使用的是UITextView
实例...但是mvvmcross vnext仅对UITextField
元素提供2向绑定.
I think the problem will be that you are using UITextView
instances... but mvvmcross vnext only ships with 2-way binding for UITextField
elements.
要将UITextView
2向绑定添加到较旧的mvvmcross版本:
To add the UITextView
2-way binding to an older mvvmcross version:
-
添加自定义目标绑定类-类似于v3中的类:在Setup.cs期间使用以下代码注册它:
Register it during Setup.cs with code like:
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry) { base.FillTargetFactories(registry); registry.RegisterFactory(new MvxSimplePropertyInfoTargetBindingFactory(typeof(MvxUITextViewTextTargetBinding), typeof(UITextView), "Text"); }
或者(但可能不在您的直接演示之前),您可以考虑更新到v3 beta版本.
Alternatively (but maybe not before your immediate demos), you could consider updating to the v3 beta release.
顺便说一句,现在通常使用"swiss"绑定语法是执行此操作的常规方法:
Incidentally, using the 'swiss' binding syntax is generally now the normal way to do this:
this.AddBindings(
new Dictionary<object, string>()
{
{lastname, "Text LastName"},
{uservin, "Text CarVIN"}
});
...和TwoWay
绑定是大多数非Windows MvvmCross绑定的默认绑定.
... and TwoWay
binding is the default for most non-Windows MvvmCross bindings.
这篇关于如何使用mvvmcross双向绑定到UITextView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!