问题
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