MvxSidebarPresentationAttribute is not configured

2019-07-13 04:45发布

问题:

Unhandled Exception

System.Collections.Generic.KeyNotFoundException: The type MvxSidebarPresentationAttribute is not configured in the presenter dictionary

  • MvvmCros 5.6 Tools
  • Visual studio 2015
  • Windows 8.1
  • iPhone 7 simulator iOS 10.3


code
Menu View

    [MvxFromStoryboard("Main")]
    [MvxSidebarPresentation(MvxPanelEnum.Left, MvxPanelHintType.PushPanel, false)]
    public partial class MenuViewController : MvxViewController<MenuViewModel>
    {
        public MenuViewController(IntPtr handle) : base(handle)
        {
        }

        public MenuViewController() : base("MenuViewController", null)
        {
        }

        public override void DidReceiveMemoryWarning()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var set = this.CreateBindingSet<MenuViewController, MenuViewModel>();
            set.Bind(btnFirst).To(vm => vm.GotoFirstView);
            set.Bind(btnSecond).To(vm => vm.GotoSecondView);
            set.Apply();
            // Perform any additional setup after loading the view, typically from a nib.
        }
}

first View

[MvxFromStoryboard("Main")]
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true)]
public partial class FirstViewController : MvxViewController<FirstViewModel>
{
    public FirstViewController() : base("FirstViewController", null)
    {
    }

    public FirstViewController(IntPtr handle) : base(handle)
    {
    }
    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        // Perform any additional setup after loading the view, typically from a nib.
    }
}

second view

[MvxFromStoryboard("Main")]
    [MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true)]
    public partial class SecondViewController : MvxViewController<SecondViewModel>
    {
        public SecondViewController() : base("SecondViewController", null)
        {
        }

        public SecondViewController(IntPtr handle) : base(handle)
        {
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
        }
    }

i have used above code in my ios project but it just showing error in ouptut as
Unhandled Exception

System.Collections.Generic.KeyNotFoundException: The type MvxSidebarPresentationAttribute is not configured in the presenter dictionary

回答1:

You have to use the MvxSidebarPresenter in the Setup.cs file of your iOS project:

protected override IMvxIosViewPresenter CreatePresenter()
{
   return new MvxSidebarPresenter((MvxApplicationDelegate)ApplicationDelegate, Window);
}

You can see the working example in the samples.