无法将 MvvMCross 6.x iOS 颜色绑定到 MvxColor WithConversion
Unable to Bind MvvMCross 6.x iOS color to MvxColor WithConversion
我是 MvvMCross 的新手,我在将我的视图模型 mvx 属性 绑定到 iOS 中的背景色时遇到问题。我从头开始建立了自己的项目,但为了确认它不在设置中,然后我使用 MvxScaffolding 创建了一个新项目。
我得到的错误是:
[ERROR] (MvxBind) Problem seen during binding execution for binding
TintColor for Colour - problem ArgumentException: Object of type
'MvvmCross.UI.MvxColor' cannot be converted to type 'UIKit.UIColor'.
查看模型:
using MvvmCross.UI;
namespace BindingTests.Core.ViewModels.Main
{
public class MainViewModel : BaseViewModel
{
public MvxColor Colour { get { return MvxColors.AliceBlue; }}
}
}
查看
using System;
using MvvmCross.Platforms.Ios.Presenters.Attributes;
using MvvmCross.Platforms.Ios.Views;
using BindingTests.Core.ViewModels.Main;
using MvvmCross.Binding.BindingContext;
namespace BindingTests.iOS.Views.Main
{
[MvxFromStoryboard(nameof(MainViewController))]
[MvxRootPresentation(WrapInNavigationController = true)]
public partial class MainViewController : BaseViewController<MainViewModel>
{
public MainViewController(IntPtr handle) : base(handle)
{
var set = this.CreateBindingSet<MainViewController, MainViewModel>();
set.Bind(LabelWelcome).For(l => l.BackgroundColor).To(vm => vm.Colour).WithConversion("NativeColor");
set.Apply();
}
}
}
有人有什么想法吗?我很难过。
进阶干杯
忘了说了,这对 MvvmCross 很好用 5.x
MvvmCross 6 提供了一种新的插件注册机制。
我们遇到了两种问题:
1) 我们在发布前没有发现的一个问题是框架现在假定插件程序集将在注册时加载。不幸的是,我们无法保证(除非显式使用程序集,否则运行时通常不会加载程序集)。
2) 链接器之前不是问题,因为框架有 bootstrap 文件,可确保代码未被删除。我们在最重要的 类 上添加了 Preserve
属性,但显然这还不够。
在我写这个答案的时候,我们正在开发一个新的实现,您可以跟踪状态 in this issue。
作为解决方法(并实际回答问题),您可以将此行添加到 iOS 上的 LinkerPleaseInclude
文件(具体采用哪种方法并不重要):var converter = new MvxNativeColorValueConverter();
.
我是 MvvMCross 的新手,我在将我的视图模型 mvx 属性 绑定到 iOS 中的背景色时遇到问题。我从头开始建立了自己的项目,但为了确认它不在设置中,然后我使用 MvxScaffolding 创建了一个新项目。
我得到的错误是:
[ERROR] (MvxBind) Problem seen during binding execution for binding
TintColor for Colour - problem ArgumentException: Object of type
'MvvmCross.UI.MvxColor' cannot be converted to type 'UIKit.UIColor'.
查看模型:
using MvvmCross.UI;
namespace BindingTests.Core.ViewModels.Main
{
public class MainViewModel : BaseViewModel
{
public MvxColor Colour { get { return MvxColors.AliceBlue; }}
}
}
查看
using System;
using MvvmCross.Platforms.Ios.Presenters.Attributes;
using MvvmCross.Platforms.Ios.Views;
using BindingTests.Core.ViewModels.Main;
using MvvmCross.Binding.BindingContext;
namespace BindingTests.iOS.Views.Main
{
[MvxFromStoryboard(nameof(MainViewController))]
[MvxRootPresentation(WrapInNavigationController = true)]
public partial class MainViewController : BaseViewController<MainViewModel>
{
public MainViewController(IntPtr handle) : base(handle)
{
var set = this.CreateBindingSet<MainViewController, MainViewModel>();
set.Bind(LabelWelcome).For(l => l.BackgroundColor).To(vm => vm.Colour).WithConversion("NativeColor");
set.Apply();
}
}
}
有人有什么想法吗?我很难过。 进阶干杯
忘了说了,这对 MvvmCross 很好用 5.x
MvvmCross 6 提供了一种新的插件注册机制。
我们遇到了两种问题:
1) 我们在发布前没有发现的一个问题是框架现在假定插件程序集将在注册时加载。不幸的是,我们无法保证(除非显式使用程序集,否则运行时通常不会加载程序集)。
2) 链接器之前不是问题,因为框架有 bootstrap 文件,可确保代码未被删除。我们在最重要的 类 上添加了 Preserve
属性,但显然这还不够。
在我写这个答案的时候,我们正在开发一个新的实现,您可以跟踪状态 in this issue。
作为解决方法(并实际回答问题),您可以将此行添加到 iOS 上的 LinkerPleaseInclude
文件(具体采用哪种方法并不重要):var converter = new MvxNativeColorValueConverter();
.