绑定到实现Xamarin.iOS应用程序的侧菜单,但在控制台中收到警告:
mvx:警告: 0.25没有发现sidemenu。若要使用sidemenu,请用“MvxPanelPresentationAttribute”类装饰视图控制器类,并将面板设置为“左”或“右”。
步骤
1)为菜单创建基类(来自示例)
public class BaseMenuViewController<T> : MvxViewController<T>, IMvxSidebarMenu where T : class, IMvxViewModel
{
public virtual UIImage MenuButtonImage => UIImage.FromBundle("burger");
public virtual bool AnimateMenu => true;
public virtual float DarkOverlayAlpha => 0;
public virtual bool HasDarkOverlay => false;
public virtual bool HasShadowing => true;
public virtual bool DisablePanGesture => false;
public virtual bool ReopenOnRotate => true;
private int MaxMenuWidth = 300;
private int MinSpaceRightOfTheMenu = 55;
public int MenuWidth => UserInterfaceIdiomIsPhone ?
int.Parse(UIScreen.MainScreen.Bounds.Width.ToString()) - MinSpaceRightOfTheMenu : MaxMenuWidth;
private bool UserInterfaceIdiomIsPhone
{
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public virtual void MenuWillOpen()
{
}
public virtual void MenuDidOpen()
{
}
public virtual void MenuWillClose()
{
}
public virtual void MenuDidClose()
{
}
}2)实现VisibleView (第一个是可见的)
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true)]
public partial class ContentViewController : MvxViewController<ContentViewModel>
{
public ContentViewController()
: base("ContentViewController", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.BackgroundColor = UIColor.Purple;
this.ViewModel.Show<MenuViewModel>();
}
}3)实现MenuElementViewController (SideMenu)
[Register("MenuViewController")]
[MvxSidebarPresentation(MvxPanelEnum.Left, MvxPanelHintType.PushPanel, false)]
public class MenuViewController : BaseMenuViewController<MenuViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.View.BackgroundColor = UIColor.Red;
}
}4)在安装程序中添加SideMenu演示程序
protected override IMvxIosViewPresenter CreatePresenter()
{
return new MvxSidebarPresenter((MvxApplicationDelegate)ApplicationDelegate, Window);
}预期行为
应该用汉堡按钮从第1点看到控制器
实际行为
来自point1的控制器变得可见,但没有汉堡包按钮,来自point2的控制器没有初始化,在控制台中警告类的装饰丢失,但正如你所看到的,它们是存在的(警告也被废弃,需要更新- 检查源代码搜索是否正确类型,但警告有旧消息。 )
配置
MvvmCross诉5.0.6
同时还看到了这个职位在寻找错误时的重新检查,看起来一切都很好,但不起作用。
警告日志:
mvx:诊断: 0.21设置:次要端 mvx:诊断: 0.21显示ViewModel ContentViewModel iOSNavigation:诊断: 0.21导航请求 警告: 0.23没有发现sidemenu。若要使用sidemenu,请用“MvxPanelPresentationAttribute”类装饰视图控制器类,并将面板设置为“左”或“右”。
我还希望在调用breakPoint时在ViewDidload for MenuViewController中看到this.ViewModel.Show<MenuViewModel>();停止,但它从未被触发,就在创建此控制器的模型的同一时刻。
有人能告诉我做错了什么吗?
编辑
我能够设置带边栏的新空项目,它的工作就像预期的那样。但是相同的代码不适用于我当前的项目--我不知道为什么不按预期读取修饰属性.
发布于 2017-07-14 13:16:29
花两天时间找出原因--与检测和解析装饰属性相关的问题。
我没有几个在彼此之间共享代码基的项目,而且由于某种原因,如果将[MvxSidebarPresentation(MvxPanelEnum.Left, MvxPanelHintType.PushPanel, false)]放在共享项目中而不是在项目本身中,则不会考虑到它。在同一时刻
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true)]
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true, MvxSplitViewBehaviour.Master)]
[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.PushPanel, true, MvxSplitViewBehaviour.Detail)]按预期工作。
解决方法是在每个项目中使用->子类共享menuClass (与MvxPanelEnum.Left)。
不确定这个问题是与mvvmCross库有关还是与Xamarin有关。
发布于 2017-07-14 09:34:47
该跟踪由MvxSidebarViewController中的这段代码触发。
protected virtual void SetupSideMenu()
{
var leftSideMenu = ResolveSideMenu(MvxPanelEnum.Left);
var rightSideMenu = ResolveSideMenu(MvxPanelEnum.Right);
if (leftSideMenu == null && rightSideMenu == null)
{
Mvx.Trace(MvxTraceLevel.Warning, $"No sidemenu found. To use a sidemenu decorate the viewcontroller class with the 'MvxPanelPresentationAttribute' class and set the panel to 'Left' or 'Right'.");
AttachNavigationController();
return;
}
// ...
}因此,Mvvmcross无法解析用上面使用的属性标记的SideMenu视图控制器。我建议移除所有的MvvmCross核,并对bin和obj文件夹进行核弹。
可能尝试向MenuViewController添加构造函数可能会有所帮助。
如果所有这些都失败了,我会尝试构建测试项目中的类,我注意到您的ContentViewController并不像在项目中那样从基类继承。我知道这不应该是真正相关的,但是从我对侧栏类的实验中发现,它对于ViewControllers和嵌套视图控制器的设置非常特殊。
我完全取消了MvvmCross siderbar nuget,只是直接使用XamarinSidebar nuget,我使用MvxSidebarViewController作为起点来创建自己的实现,我对属性设置并不特别感兴趣,我喜欢自己来处理导航,而不是使用ShowViewModel或新的导航系统。
希望这能帮上忙。
https://stackoverflow.com/questions/45082154
复制相似问题