MVVMCross iOS 自定义可见性转换器未被调用
MVVMCross iOS custom visibility converter not being called
我有一个在 Android 上完美运行的列表可见性转换器,但我无法在 iOS 中调用 Convert 方法。
public class ListVisibilityConverter : MvxBaseVisibilityValueConverter<IList>
{
protected override MvxVisibility Convert(IList value, object parameter, CultureInfo culture)
{
var inverse = false;
if (parameter != null)
{
inverse = (bool)parameter;
}
var listHasEntries = (value != null) && value.Count > 0;
if (inverse)
{
return listHasEntries ? MvxVisibility.Collapsed : MvxVisibility.Visible;
}
else
{
return listHasEntries ? MvxVisibility.Visible : MvxVisibility.Collapsed;
}
}
}
我在 ViewController...
的 ViewDidLoad 中的绑定中使用转换器
var set = this.CreateBindingSet<AddFriendsFromContactsViewController, AddFriendsFromContactsViewModel>();
set.Bind(collectionView).For("Visibility").To(vm => vm.SectionedCollection).WithConversion("ListVisibility", true);
set.Bind(noContactsFoundLabel).For("Visibility").To(vm => vm.SectionedCollection).WithConversion("ListVisibility", false);
set.Apply();
在 Setup.cs 中,我已确认使用以下代码找到转换器...
protected override void InitializeLastChance()
{
base.InitializeLastChance();
var registry = Mvx.Resolve<IMvxValueConverterLookup>();
var f = registry.Find(BindingStrings.ListVisibility);
Mvx.Trace("Custom converter was found : {0}", f != null);
}
在 iOS 项目的设置中覆盖 ValueConverterAssemblies 并手动添加值转换器解决了这个问题。
protected override IEnumerable<Assembly> ValueConverterAssemblies
{
get
{
var assemblies = base.ValueConverterAssemblies;
var valueConverterAssemblies = assemblies as Assembly[] ?? assemblies.ToArray();
valueConverterAssemblies.ToList().Add(typeof(ListVisibilityConverter).Assembly);
return valueConverterAssemblies;
}
}
我有一个在 Android 上完美运行的列表可见性转换器,但我无法在 iOS 中调用 Convert 方法。
public class ListVisibilityConverter : MvxBaseVisibilityValueConverter<IList>
{
protected override MvxVisibility Convert(IList value, object parameter, CultureInfo culture)
{
var inverse = false;
if (parameter != null)
{
inverse = (bool)parameter;
}
var listHasEntries = (value != null) && value.Count > 0;
if (inverse)
{
return listHasEntries ? MvxVisibility.Collapsed : MvxVisibility.Visible;
}
else
{
return listHasEntries ? MvxVisibility.Visible : MvxVisibility.Collapsed;
}
}
}
我在 ViewController...
的 ViewDidLoad 中的绑定中使用转换器var set = this.CreateBindingSet<AddFriendsFromContactsViewController, AddFriendsFromContactsViewModel>();
set.Bind(collectionView).For("Visibility").To(vm => vm.SectionedCollection).WithConversion("ListVisibility", true);
set.Bind(noContactsFoundLabel).For("Visibility").To(vm => vm.SectionedCollection).WithConversion("ListVisibility", false);
set.Apply();
在 Setup.cs 中,我已确认使用以下代码找到转换器...
protected override void InitializeLastChance()
{
base.InitializeLastChance();
var registry = Mvx.Resolve<IMvxValueConverterLookup>();
var f = registry.Find(BindingStrings.ListVisibility);
Mvx.Trace("Custom converter was found : {0}", f != null);
}
在 iOS 项目的设置中覆盖 ValueConverterAssemblies 并手动添加值转换器解决了这个问题。
protected override IEnumerable<Assembly> ValueConverterAssemblies
{
get
{
var assemblies = base.ValueConverterAssemblies;
var valueConverterAssemblies = assemblies as Assembly[] ?? assemblies.ToArray();
valueConverterAssemblies.ToList().Add(typeof(ListVisibilityConverter).Assembly);
return valueConverterAssemblies;
}
}