我在一个名为 BorderColor 的字符串类型的 View 模型上有一个属性,我尝试将它绑定(bind)到 UIView.Layer.BorderColor,这是绑定(bind)语法:
set.Bind (this.MyUIView).For ("Layer.BorderColor").To (t => t.BorderColor).WithConversion (new StringToColorConverter { ToCGColor = true });
但是,如果我说直接在 UIView 上绑定(bind)到 BackgroundColor 属性,它不起作用,它就像一个魅力。有人知道 MvvmCross 是否支持绑定(bind)到 Layer 属性?
我尝试了目标路径的不同变体,例如“Layer.BorderColor”,并强输入了 t=>Layer.BorderColor,没有运气。
最佳答案
来自 https://github.com/MvvmCross/MvvmCross/wiki/Databinding#fluent 的流畅绑定(bind)语法的描述
The fluent syntax provides a C# way to create bindings.
This syntax is generally done using the CreateBindingSet helper.
The syntax includes:
Bind($ViewObject$)
where $ViewObject$ is the view target for binding.
For(v => v.$ViewProperty$)
where $ViewProperty$ is the property on the view for binding.
所以......你可以尝试使用:
set.Bind (this.MyUIView.Layer).For ("BorderColor")...
只要没有人更改
Layer
,这应该可以工作。本身 - 如果您需要比这更复杂的绑定(bind),那么您需要创建一个自定义绑定(bind)(参见 N+1 系列中的示例)。
关于ios - MvvmCross - 如何将 UIView.Layer.AnyProperty (Xamarin.iOS) 绑定(bind)到 View 模型上的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26239110/