我試圖改變綁定BackgroundColor屬性的微調框的背景顏色,如下所示,但它沒有任何效果。MvvmCross中的背景顏色綁定
View.axml
<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
android:layout_width="115dp"
android:layout_height="match_parent"
android:textColor="@color/primary_text"
local:MvxItemTemplate="@layout/single"
local:MvxBind="ItemsSource SingleList; SelectedItem SingleSize ; BackgroundColor SingleBackgroundValueConverter(IsSingleValid)" />
Converter.cs
public class SingleBackgroundValueConverter: MvxValueConverter<bool>
{
protected override MvxColor Convert(bool value, object parameter, CultureInfo culture)
{
// either white or red
return value ? new MvxColor(255, 255, 255) : new MvxColor(255, 0, 0);
}
}
在下面,我能看到警告彈出,但背景顏色並沒有改變。
ViewModel.cs
public void Save()
{
if (!isExist)
{
OnExit(this, null);
}
else
{
_isSingleValid= false;
RaisePropertyChanged(() => IsSingleValid);
Mvx.Resolve<IUserDialogs>().Alert("It is not valid");
}
}
private bool _isSingleValid = true;
public bool IsSingleValid
{
get { return _isSingleValid; }
set
{
_isSingleValid= value;
RaisePropertyChanged(() => IsSingleValid);
}
}
我認爲您的轉換器的方法簽名被複制錯誤,因爲它缺少類型參數,應該無法編譯。它應該像'保護覆蓋MvxColor轉換(布爾值,類型targetType,對象參數,CultureInfo文化)'?而轉換器繼承應該需要輸出類型:'MvxValueConverter'? –
Plac3Hold3r