【问题标题】:Link in ToolbarItem not workingToolbarItem 中的链接不起作用
【发布时间】:2017-11-12 00:25:29
【问题描述】:

我是 xamarin 表单的新手,我设法通过这种方式在应用程序中放置了一个菜单工具栏:

    <ContentPage.ToolbarItems>
    <ToolbarItem Text="Test text"
                 Icon="add.png"
                 Priority="0"
                 Order="Primary"
                 Clicked="MenuItem_OnClicked"
                 />
     </ContentPage.ToolbarItems>

我想将用户带到我已经创建的另一个页面,但是我尝试在相关的 .cs 文件上使用它,作为我想要将用户重定向到的页面的 ConstAvances:

  private async void MenuItem_OnClicked(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new ConstAvances { Title = "Example title" });

    }

然后什么也没有发生。在该应用程序的其他网站上,我使用了类似的方法并且它有效。我在这里错过了什么吗?有人可以指出我正确的方向吗? 谢谢。

【问题讨论】:

  • 你能看到工具栏项吗?你能按项目吗?代码似乎是正确的。
  • 是的,我可以看到它,我可以点击它但是当我点击它时没有任何反应

标签: xaml xamarin xamarin.forms


【解决方案1】:

确保你的代码中有这个。

public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();

    }
    // This is your toolbar's click event
    private void MenuItem_OnClicked(object sender, EventArgs e)
    {
        DisplayAlert("Test", "Display alert", "OK");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 2014-11-30
    • 1970-01-01
    • 2016-02-25
    • 2013-12-31
    相关资源
    最近更新 更多