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