工具栏项目未以xamarin形式显示 [英] Toolbar item not showing in xamarin forms

查看:114
本文介绍了工具栏项目未以xamarin形式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xamarin表格几乎是新手。
我正在尝试将工具栏项添加到内容页面。

I am pretty much new to Xamarin forms. I am trying to add toolbar items to content page.

我使用IPAD Air作为部署设备,并使用了服务器的iPhone / ipad模拟器。
我参考了XamarinForms-Mobile App pdf文档。虽然它是基本的,但我不确定,为什么我无法在设备中看到它。请帮助我在哪里犯错误。

I am using IPAD Air as deployment device and used sever iPhone/ipad simulators as well. I referred the XamarinForms-Mobile App pdf document. Though its a basic, i am not sure, why i am not able to see it in device. Please help me where i am making the mistake.

public partial class SamplePage : ContentPage   
{
    public SamplePage()
    {
        //Toolbar items
            ToolbarItem scanItem = new ToolbarItem ();
            scanItem.Name = "Scan";
            scanItem.Order = ToolbarItemOrder.Primary;

            ToolbarItem settingsItem = new ToolbarItem ();
            settingsItem.Name = "Settings";
            settingsItem.Order = ToolbarItemOrder.Primary;

            ToolbarItems.Add (scanItem);
            ToolbarItems.Add (settingsItem);
    }
}

App.cs

public class App
    {
        public static Page GetMainPage ()
        {   
            return new SamplePage ();
        }
    }

尝试了xaml的做法。但没有结果。内容页面为空白。

Tried xaml way of doing it as well. But no result. Content page is blank.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BLE_Core.BLECorePage">
    <ContentPage.Content>
    </ContentPage.Content>
    <ContentPage.ToolbarItems>
        <ToolbarItem Name = "Scan"></ToolbarItem>
        <ToolbarItem Name = "Settings"></ToolbarItem>
   </ContentPage.ToolbarItems>
</ContentPage>


推荐答案

如果您的应用没有,您的ToolbarItems将不会显示工具栏。添加一个的最简单方法是将页面包装在NavigationPage中

Your ToolbarItems will not show if your app does not have a Toolbar. The simplest way to add one is to wrap your page in a NavigationPage

public static Page GetMainPage ()
{   
  return new NavigationPage(new SamplePage ());
}

这篇关于工具栏项目未以xamarin形式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆