ios - MvvmCross:如何将 FlyoutNavigation 组件与 MvvmCross 一起使用
<p><p>有没有关于如何将 MvvmCross 与 Xamarin 的 FlyoutNavigation 组件一起使用的示例。</p>
<p>当我尝试使用 MainNavigationViewModel 中的菜单 View 设置 ViewControllers 时出现错误。这是我得到的错误“System.Reflection.TargetInvocationException:调用的目标已引发异常。”</p>
<p>这是我的示例代码:</p>
<pre><code>public class MainNavigationViewModel : MvxViewModel
{
public MainNavigationViewModel()
{
MenuOne = new MenuOneViewModel();
}
private MenuOne _MenuOne;
public MenuOneViewModel MenuOne
{
get { return _MenuOne; }
set
{
_MenuOne = value;
RaisePropertyChanged(() => MenuOne);
}
}
}
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;
viewControllers = 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;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个例子 <a href="https://github.com/fcaico/MvxSlidingPanels.Touch" rel="noreferrer noopener nofollow">https://github.com/fcaico/MvxSlidingPanels.Touch</a>它基于该组件的一个分支</p></p>
<p style="font-size: 20px;">关于ios - MvvmCross:如何将 FlyoutNavigation 组件与 MvvmCross 一起使用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18324740/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18324740/
</a>
</p>
页:
[1]