MvvmCross - How to bind UIView.Layer.AnyProperty (Xamarin.iOS) to a property on a viewmodel?

那年仲夏 提交于 2019-12-11 03:09:14

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/26239110/mvvmcross-how-to-bind-uiview-layer-anyproperty-xamarin-ios-to-a-property-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!