MvvmCross-如何将UIView.Layer.AnyProperty(Xamarin.iOS)绑定到视图模型上的属性? [英] MvvmCross - How to bind UIView.Layer.AnyProperty (Xamarin.iOS) to a property on a viewmodel?

查看:80
本文介绍了MvvmCross-如何将UIView.Layer.AnyProperty(Xamarin.iOS)绑定到视图模型上的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为stringcolor的视图模型的视图模型上有一个属性,我尝试将其绑定到UIView.Layer.BorderColor,这是绑定语法:

set.Bind (this.MyUIView).For ("Layer.BorderColor").To (t => t.BorderColor).WithConversion (new StringToColorConverter { ToCGColor = true });

它不起作用,但是,如果我说直接在UIView上绑定到BackgroundColor属性,它的工作原理就像是一种魅力.有人知道MvvmCross是否支持对Layer属性的绑定?

我尝试了目标路径的不同变体,例如"Layer.BorderColor",并强类型输入t => Layer.BorderColor,不走运.

解决方案

https://github.com/MvvmCross/MvvmCross/wiki/Databinding#fluent

流利的语法提供了一种创建绑定的C#方法.

通常使用CreateBindingSet帮助器完成此语法.

语法包括:

       Bind($ViewObject$) 

其中$ ViewObject $是绑定的视图目标.

       For(v => v.$ViewProperty$) 

其中$ ViewProperty $是视图上用于绑定的属性.

所以...您可以尝试使用:

     set.Bind (this.MyUIView.Layer).For ("BorderColor")...

只要没有人更改Layer本身,它就应该起作用-如果您需要比这更复杂的绑定,则需要创建一个自定义绑定(请参阅N + 1系列中的示例). /p>

I have a property on a view model called BorderColor of type string, and I try to bind it to UIView.Layer.BorderColor, here's the binding sytax:

set.Bind (this.MyUIView).For ("Layer.BorderColor").To (t => t.BorderColor).WithConversion (new StringToColorConverter { ToCGColor = true });

It doesnt work, however, if I say bind to BackgroundColor property directly on a UIView, it works like a charm. Anybody knows if binding to Layer property is supported by MvvmCross?

I tried different variations of the target path, like "Layer.BorderColor", and strongly typed t=>Layer.BorderColor, no luck.

解决方案

From the description of the fluent binding syntax at https://github.com/MvvmCross/MvvmCross/wiki/Databinding#fluent

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.

So ... you could try using:

     set.Bind (this.MyUIView.Layer).For ("BorderColor")...

This should work as long as no-one changes the Layer itself - if you need more complicated binding than that, then you'd need to create a custom binding (see examples in the N+1 series).

这篇关于MvvmCross-如何将UIView.Layer.AnyProperty(Xamarin.iOS)绑定到视图模型上的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆