0
我用我的Xamarin.Android项目中MVVM光想我MainViewModel
的StatusColor
属性绑定到GradientDrawable
其充当ImageView
控制的背景的背景光MVVM 。绑定Drawble背景颜色与Xamarin.Android
不幸的是,GradientDrawable
没有任何Color
属性,我可以绑定我的颜色,只是一个SetColor(int)
方法。当我的MainViewModel
的StatusColor
属性发生变化时,是否有办法告诉MVVM灯始终调用此方法SetColor(int)
?
丑陋的替代方法是当视图模型改变了颜色属性触发事件,但我真的想避免...
我的代码目前看起来是这样的(!):
// This does not work!
this.SetBinding(
() => MainViewModel.StatusColor,
() => ((GradientDrawable)IvStatus.Background).Color); // There is no GradientDrawable.Color property...
如果有帮助,这是我IvStatus
控制和Drawable
其背景设置为:
IvStatus
:
<ImageView
android:id="@+id/ivStatus"
android:background="@drawable/Circle"
android:layout_width="10dip"
android:layout_height="10dip"
android:layout_gravity="center_vertical" />
Circle.xml
:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#cccccc"/>
<stroke
android:width="1dip"
android:color="#333333"/>
</shape>
提前感谢!
我不认为你可以。也许看看MvvmCross库,他们可能有一个绑定解决方法。但据我所知MvvmLight你应该只是订阅属性更改事件,在你的Android应用程序,并手动创建一个新的GradientBrush当你的虚拟机中的颜色值改变 – Miiite