是否有关于如何使用Xamarin的FlyoutNavigation组件使用MvvmCross的示例。
当我尝试使用MainNavigationViewModel的菜单视图设置ViewControllers时出现错误。这是我得到的错误“System.Reflection.TargetInvocationException:调用的目标抛出了异常。”
以下是我的示例代码:
public class MainNavigationViewModel : MvxViewModel
{
public MainNavigationViewModel()
{
MenuOne = new MenuOneViewModel();
}
private MenuOne _MenuOne;
public MenuOneViewModel MenuOne
{
get { return _MenuOne; }
set
{
_MenuOne = value;
RaisePropertyChanged(() => MenuOne);
}
}
}
[Register("MainNavigationView")]
public sealed class MainNavigationView : MvxViewController
{
protected MainNavigationViewModel MainNavViewModel
{ get { return base.ViewModel as MainNavigationViewModel; } }
public MainNavigationView()
{
ViewDidLoad();
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
NavigationController.NavigationBarHidden = true;
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (ViewModel == null)
return;
var flyoutNavigationController = new FlyoutNavigationController();
var menuViewRoot = new RootElement(null);
var menuItems = new List<StringElement>()
{
new StringElement("Menu One")
};
var menuSection = new Section("Main Menu") { menuItems };
menuViewRoot.Add(menuSection);
flyoutNavigationController.NavigationRoot = menuViewRoot;
var viewControllers = new UIViewController[1];
viewControllers[0] = CreateMenuItemController(MainNavViewModel.MainOne);
flyoutNavigationController.ViewControllers = viewControllers;
flyoutNavigationController.View.Frame = UIScreen.MainScreen.Bounds;
flyoutNavigationController.ToggleMenu();
Add(flyoutNavigationController.View);
}
private UIViewController CreateMenuItemController(IMvxViewModel viewModel)
{
var controller = new UINavigationController();
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
controller.PushViewController(screen, false);
return controller;
}
}