【问题标题】:Xamarin menu with ToolbarItem icon带有 ToolbarItem 图标的 Xamarin 菜单
【发布时间】:2017-03-09 08:40:48
【问题描述】:

我想做类似这个例子的事情,但我做不到。 我尝试了很多插件,但我找不到实现的方法。

有人知道或可以告诉我该怎么做吗?

我想在单击 MasterDetailPage 上的一个 ToolbarItem 时显示一个显示弹出菜单。

我的实际应用:

我想要什么:

【问题讨论】:

    标签: c# .net xamarin cross-platform toolbaritems


    【解决方案1】:

    我想你可以看看SlideOverKit

    public SlideDownMenuView ()
    {
        InitializeComponent ();
    
        // You must set HeightRequest in this case
        this.HeightRequest = 600;
        // You must set IsFullScreen in this case, 
        // otherwise you need to set WidthRequest, 
        // just like the QuickInnerMenu sample
        this.IsFullScreen = true;
        this.MenuOrientations = MenuOrientation.TopToBottom;
    
        // You must set BackgroundColor, 
        // and you cannot put another layout with background color cover the whole View
        // otherwise, it cannot be dragged on Android
        this.BackgroundColor = Color.FromHex ("#D8DDE7");         
    }
    

    否则enter link description here

    你可以试试这段代码...

    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
    
            MasterDetailPage mdpage = new MasterDetailPage();
            mdpage.Master = new ContentPage() { Title = "Master", BackgroundColor = Color.Red };
            ToolbarItem tbi = new ToolbarItem() { Text = "POPUP" };
            tbi.Clicked += async (object sender, System.EventArgs e) => {
    
                StackLayout sl = new StackLayout() { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.Pink, WidthRequest  = 100, HeightRequest = 200 };
                Rg.Plugins.Popup.Pages.PopupPage mypopup = new Rg.Plugins.Popup.Pages.PopupPage() {BackgroundColor = Color.Transparent };
                mypopup.Content = sl;
                await MainPage.Navigation.PushPopupAsync(mypopup);
            };
            ContentPage detail = new ContentPage() { Title = "Detail", BackgroundColor = Color.Green,  };
            detail.ToolbarItems.Add(tbi);
            mdpage.Detail = new NavigationPage(detail);
            MainPage = mdpage;
        }
    
        protected override void OnStart()
        {
            // Handle when your app starts
        }
    
        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }
    
        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
    

    【讨论】:

    • 我使用 SlideOverKit 在 Tabbedpage 中显示一个菜单 BottomToTop 并且工作正常,但是不能像你说的那样将它分配给 toptobottom,因为它是一个 MasterDetailPage,我不知道如何实现它。
    • 这个插件你试过了吗github.com/rotorgames/Rg.Plugins.Popup
    • 是的,但是它不起作用,它显示得很糟糕并且使后窗变暗,我只想显示一个下拉菜单..这是我的代码:
    • 非常感谢,它与该代码完美配合!! :)
    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2017-08-14
    • 2013-02-02
    相关资源
    最近更新 更多