首页 \ 问答 \ SideMenu for mvvmCross(SideMenu for mvvmCross)

SideMenu for mvvmCross(SideMenu for mvvmCross)

Xamarin.iOS应用程序实现侧面菜单,但在控制台中收到警告:

mvx:警告:0.25没有发现侧面菜单。 要使用sidemenu使用'MvxPanelPresentationAttribute'类装饰viewcontroller类,并将面板设置为'Left'或'Right'。

脚步

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)在Setup中为SideMenu添加演示者

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

预期的行为

应该从汉堡点按钮看点控制器

实际行为

来自point1的控制器变得可见,但是没有汉堡按钮,来自point2的控制器未初始化,在控制台中警告关于错过的类装饰,但是当你看到它们存在时(同样警告已弃用且需要更新 - 检查源代码 - 搜索完成正确类型,但警告有旧消息

组态

MvvmCross v 5.0.6

  • MvvmCross
  • MvvmCross.Core
  • MvvmCross.Binding
  • MvvmCross.iOS.Support
  • MvvmCross.iOS.Support.XamarinSidebar
  • MvvmCross.Platform
  • SidebarNavigation

在查找错误时也看到了这篇文章 - 重新检查,看起来一切都很好,但不行。

警告日志:

mvx:诊断:0.21设置:次要结束

mvx:Diagnostic:0.21显示ViewModel ContentViewModel iOS导航:诊断:0.21导航请求

mvx:警告:0.23没有发现侧面菜单。 要使用sidemenu使用'MvxPanelPresentationAttribute'类装饰viewcontroller类,并将面板设置为'Left'或'Right'。

我还希望在调用this.ViewModel.Show<MenuViewModel>();时看到ViewDidload中的ViewDidloadMenuViewController停止this.ViewModel.Show<MenuViewModel>(); 但它永远不会被触发,在此控制器创建的同一时刻模型中。

有人可以建议做错了吗?


编辑

我能够使用侧边栏设置新的空项目,并且按预期工作。 但是相同的代码在我当前的项目中不起作用 - 我不知道为什么装饰属性没有按预期读取....


Tying to implement side menu for Xamarin.iOS app, but got warning in console:

mvx:Warning: 0.25 No sidemenu found. To use a sidemenu decorate the viewcontroller class with the 'MvxPanelPresentationAttribute' class and set the panel to 'Left' or 'Right'.

Steps

1) Create base class for menu (from sample)

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) Implement VisibleView (First one that will be visible)

[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) Implement 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) Add presenter for SideMenu in Setup

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

Expected behavior

Should see controller from point 1 with burger button

Actual behavior

Controller from point1 become visible but without burger button, Controller from point2 not initialized, Warning in console about missed decoration for class, but as u see they are present (also warnings deprecated and need to be updated - check source code - searching done for correct type, but warning has old message )

Configuration

MvvmCross v 5.0.6

  • MvvmCross
  • MvvmCross.Core
  • MvvmCross.Binding
  • MvvmCross.iOS.Support
  • MvvmCross.iOS.Support.XamarinSidebar
  • MvvmCross.Platform
  • SidebarNavigation

Also saw this post while looking for error - recheck and looks like everything is fine, but not work.

Warning log:

mvx:Diagnostic: 0.21 Setup: Secondary end

mvx:Diagnostic: 0.21 Showing ViewModel ContentViewModel iOSNavigation:Diagnostic: 0.21 Navigate requested

mvx:Warning: 0.23 No sidemenu found. To use a sidemenu decorate the viewcontroller class with the 'MvxPanelPresentationAttribute' class and set the panel to 'Left' or 'Right'.

I also expect to see breakPoint stop in ViewDidload for MenuViewController when call this.ViewModel.Show<MenuViewModel>(); but it's never triggered, in same moment model for this controller created.

Can someone advice what was done incorrect?


EDIT

I was able to setup new empty project with sidebar and it's work as expected. But same code not work in my current projects - I don't know why decorated attributes are not read as expected....


原文:https://stackoverflow.com/questions/45082154
更新时间:2022-06-01 22:06

最满意答案

设置

display: inline-block

将允许您在宽度方向上实现所需的结果,但也意味着元素将以内联方式显示,即,如果它们适合,则彼此相邻。
您可以通过将元素包装在块样式容器中来避免这种情况。 虽然这听起来很不理想,但这是我头脑中第一个有效的想法。

扩展您的进一步问题,您可以浮动这些元素,将它们包装在也显示为内联的容器中,然后使用RúnarBerg建议的空块来阻止它们。

请参阅示例jsFiddle
Clearfix参考

HTML:

ACTUAL:
<div></div>
<div class="wrapper cf">
<div class="flex-text">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
</div>
<div class="flex-text">
    Lorem ipsum dolor sit amet.
</div>
<div class="flex-text">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div>
</div>
<div></div>
Further content

CSS:

.flex-text {
    min-width: 200px;
    max-width: 400px;
    display: inline-block;
    background: #def;
    float: left;
    clear: both;
}

/* this is just to show a 200px ruler for reference */
.flex-text:after {
    content: "";
    display: block;
    width: 200px;
    border-top: 4px solid black;
    margin: 0 0 20px 0;
}

.wrapper {
    display: inline-block;
    background: lightblue;
}

.cf:before,
.cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}
.cf:after {
    clear: both;
}
.cf {
    *zoom: 1;
}

Setting

display: inline-block

will allow you to achieve the desired result width-wise, but will also mean the elements will be displayed inline, that is, next to one another if they fit.
You can avoid this by wrapping your elements in block-style containers. While this sounds far from ideal it's the first idea off the top of my head that works.

Expanding on your further question, you can float these elements, wrap them in a container that's also displayed inline and then block it using Rúnar Berg's suggestion of empty blocks.

See sample jsFiddle
Clearfix reference

HTML:

ACTUAL:
<div></div>
<div class="wrapper cf">
<div class="flex-text">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
</div>
<div class="flex-text">
    Lorem ipsum dolor sit amet.
</div>
<div class="flex-text">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div>
</div>
<div></div>
Further content

CSS:

.flex-text {
    min-width: 200px;
    max-width: 400px;
    display: inline-block;
    background: #def;
    float: left;
    clear: both;
}

/* this is just to show a 200px ruler for reference */
.flex-text:after {
    content: "";
    display: block;
    width: 200px;
    border-top: 4px solid black;
    margin: 0 0 20px 0;
}

.wrapper {
    display: inline-block;
    background: lightblue;
}

.cf:before,
.cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}
.cf:after {
    clear: both;
}
.cf {
    *zoom: 1;
}

相关问答

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)