有没有关于如何将 MvvmCross 与 Xamarin 的 FlyoutNavigation 组件一起使用的示例。
当我尝试使用 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;
}
}