cas*_*las 4 c# mvvmcross xamarin
我正在尝试使用绑定BackgroundColor属性更改微调器的背景颜色,如下所示,但它没有任何效果.
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)" />
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
在下面,我能够看到警报弹出,但背景颜色根本没有变化.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
Sve*_*übe 10
BackgroundColor是Color pluign的一部分.
第一步是确保已安装它.
Install-Package MvvmCross.Plugin.Color
Run Code Online (Sandbox Code Playgroud)
然后继承您的转换器MvxColorValueConverter<T>.
public class SingleBackgroundValueConverter : MvxColorValueConverter<bool>
{
protected override MvxColor Convert(bool value, object parameter, CultureInfo culture)
{
return value ? new MvxColor(255, 255, 255) : new MvxColor(255, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
然后你必须在绑定中更改转换器名称,因为mvvmcross命名约定会剥离ValueConverter部件.
local:MvxBind="ItemsSource SingleList; SelectedItem SingleSize ; BackgroundColor SingleBackground(IsSingleValid)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2737 次 |
| 最近记录: |