简体   繁体   中英

Unable to Bind MvvMCross 6.x iOS color to MvxColor WithConversion

I am fairly new to MvvMCross and I am having an issue binding my view model mvx property to a background color in iOS. I had set up my own project from scratch but to confirm it was not something in the setup I then used MvxScaffolding to create a new project.

Error I get is:

 [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'.

View Model:

using MvvmCross.UI;

namespace BindingTests.Core.ViewModels.Main
{
    public class MainViewModel : BaseViewModel
    {

        public MvxColor Colour { get { return MvxColors.AliceBlue; }}
    }
}

View

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();
        }
    }
}

Does anyone have any ideas? I'm stumped. Cheers in advanced

Forgot to mention, this works fine with MvvmCross 5.x

MvvmCross 6 comes with a new mechanism for registering Plugins.

We are experiencing two kind of issues with it:

1) One problem we didn't detect before releasing is that the framework now assumes plugin assemblies are going to be loaded by the time they are registered. Unfortunately there is no way we can guarantee that (assemblies are normally not loaded by the runtime until / unless they are explicitly used).

2) Linker was not a problem before because the framework had bootstrap files which ensured the code was not removed. We added Preserve attributes over the most important classes, but apparently it´s not enough.

At the time I'm writing this answer we are working on a new implementation, you can track the status in this issue .

As a workaround (and to actually answer the question), you can add this line to your LinkerPleaseInclude file on iOS (it doesn't matter exactly under which method): var converter = new MvxNativeColorValueConverter(); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM