1
votes

I have layout with SwitchCompat binding to ViewModel

<android.support.v7.widget.SwitchCompat 
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:MvxBind="Checked FlashlightEnabled;
                         Click FlashlightCheckedCommand"/>

I also add in LinkerPleaseInclude.cs file some Include methods

public void Include(Switch s)
        {
            s.CheckedChange += (sender, args)
                => s.Checked = !s.Checked;
            s.Checked = true;
        }

        public void Include(SwitchCompat sc)
        {
            sc.CheckedChange += (sender, args)
                => sc.Checked = !sc.Checked;
            sc.Checked = true;
        }

But when I set the Sdk and User Assemblies linking, my Checked binding is removed.

Output Message:

2018-10-16 12:31:17 [WARN] (MvxBind) Failed to create target binding for binding Checked for FlashlightEnabled10-16 12:31:17.143 I/mono-stdout( 5716): at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[]

enter image description here

1
Can you verify that SwitchCompat which is referenced in LinkerPleaseInclude.cs is from the package of version v7? - foxanna
Yes, I checked and added a picture to the question - Nikita Goncharuk
Have you tried all the first-aid tricks like deleting bin/obj/vs folders, deleting packages folder and restoring them? - foxanna
Yes it did not help - Nikita Goncharuk
@NikitaGoncharuk, could you enable all "Common Language Runtime Exceptions" in Exception Settings. This may help give you an idea as to what the exception is. From your extract System.Activator.CreateInstance it seems like it is a type instance creation that is failing. - Plac3Hold3r

1 Answers

0
votes

Make sure you've added [Android.Runtime.Preserve(AllMembers = true)] to your LinkerPleaseInclude class. If not the class will be ignored.

Here you have the latest LinkerPleaseInclude please be sure you have the same:

using Android.App;
using Android.Views;
using Android.Widget;
using MvvmCross.Binding.BindingContext;
using MvvmCross.Navigation;
using MvvmCross.ViewModels;
using System;
using System.Collections.Specialized;
using System.Windows.Input;

namespace $YourNameSpace$
{
    // This class is never actually executed, but when Xamarin linking is enabled it does how to ensure types and properties
    // are preserved in the deployed app
    [Android.Runtime.Preserve(AllMembers = true)]
    public class LinkerPleaseInclude
    {
        public void Include(Button button)
        {
            button.Click += (s, e) => button.Text = button.Text + "";
        }

        public void Include(CheckBox checkBox)
        {
            checkBox.CheckedChange += (sender, args) => checkBox.Checked = !checkBox.Checked;
        }

        public void Include(Switch @switch)
        {
            @switch.CheckedChange += (sender, args) => @switch.Checked = [email protected];
        }

        public void Include(View view)
        {
            view.Click += (s, e) => view.ContentDescription = view.ContentDescription + "";
        }

        public void Include(TextView text)
        {
            text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
        }

        public void Include(CheckedTextView text)
        {
            text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
            text.Hint = "" + text.Hint;
        }

        public void Include(CompoundButton cb)
        {
            cb.CheckedChange += (sender, args) => cb.Checked = !cb.Checked;
        }

        public void Include(SeekBar sb)
        {
            sb.ProgressChanged += (sender, args) => sb.Progress = sb.Progress + 1;
        }

        public void Include(RadioGroup radioGroup)
        {
            radioGroup.CheckedChange += (sender, args) => radioGroup.Check(args.CheckedId);
        }

        public void Include(RadioButton radioButton)
        {
            radioButton.CheckedChange += (sender, args) => radioButton.Checked = args.IsChecked;
        }

        public void Include(RatingBar ratingBar)
        {
            ratingBar.RatingBarChange += (sender, args) => ratingBar.Rating = 0 + ratingBar.Rating;
        }

        public void Include(Activity act)
        {
            act.Title = act.Title + "";
        }

        public void Include(INotifyCollectionChanged changed)
        {
            changed.CollectionChanged += (s, e) => { var test = $"{e.Action}{e.NewItems}{e.NewStartingIndex}{e.OldItems}{e.OldStartingIndex}"; };
        }

        public void Include(ICommand command)
        {
            command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
        }

        public void Include(MvvmCross.IoC.MvxPropertyInjector injector)
        {
            injector = new MvvmCross.IoC.MvxPropertyInjector();
        }

        public void Include(System.ComponentModel.INotifyPropertyChanged changed)
        {
            changed.PropertyChanged += (sender, e) =>
            {
                var test = e.PropertyName;
            };
        }

        public void Include(MvxTaskBasedBindingContext context)
        {
            context.Dispose();
            var context2 = new MvxTaskBasedBindingContext();
            context2.Dispose();
        }

        public void Include(MvxNavigationService service, IMvxViewModelLoader loader)
        {
            service = new MvxNavigationService(null, loader);
        }

        public void Include(ConsoleColor color)
        {
            Console.Write("");
            Console.WriteLine("");
            color = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.ForegroundColor = ConsoleColor.DarkGray;
        }
    }
}