xamarin.forms 不显示 ToolbarItem [英] xamarin.forms not showing ToolbarItem

查看:36
本文介绍了xamarin.forms 不显示 ToolbarItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了一个空的 xamarin.forms 项目,里面什么也没有.

I just created empty xamarin.forms project and nothing in it.

我搜索了如何添加工具栏,在 Microsoft 文档中说将这些行添加到 xaml 文件中.

I searched on how to add Toolbar, in Microsoft documentation say add these line to xaml file.

    <ContentPage.ToolbarItems>
    <ToolbarItem Text="Example Item"
                 IconImageSource="example_icon.png"
                 Order="Primary"
                 Priority="0" />
    </ContentPage.ToolbarItems>

但我的 android 设备上没有显示工具栏,这真的很难过,因为这是我第一次使用 xamarin,这只是一个空项目,但它不起作用.

But not toolbar is showing on my android device, this is really sad because this is my first time using xamarin and this is just empty project but it is not working.

这是我的主要 xaml 文件

this is my main xaml file

 <?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="test3.MainPage">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="sssssssss Item"
                 Order="Primary"
                 Priority="0" />
    </ContentPage.ToolbarItems>
    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage>

推荐答案

你的 App.xaml.cs 应该类似于:-

Your App.xaml.cs should be similar to this:-

public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new NavigationPage(new test3.MainPage());
        }

        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
        }
    }

这篇关于xamarin.forms 不显示 ToolbarItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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