xamarin.forms - xamarin.forms 未显示 ToolbarItem
问题描述
我刚刚创建了空的 xamarin.forms 项目,其中没有任何内容。
我搜索了如何添加工具栏,在 Microsoft 文档中说将这些行添加到 xaml 文件。
<ContentPage.ToolbarItems>
<ToolbarItem Text="Example Item"
IconImageSource="example_icon.png"
Order="Primary"
Priority="0" />
</ContentPage.ToolbarItems>
但是我的android设备上没有显示工具栏,这真的很伤心,因为这是我第一次使用xamarin,这只是一个空项目,但它不起作用。
这是我的主要 xaml 文件
<?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 应该与此类似:-
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
}
}
推荐阅读
- cypress - 使用 Cypress 检查项目是否在列表中。如果是,点击打开它,否则创建它
- mysql - 2 在一个中选择语句
- javascript - 从 vue 组合 API 将项目对象添加到数组
- azure - 如何自定义 Azure B2C 登录页面中的按钮和链接标签?
- windows - 批处理文件根据机器给出不同的值?
- javascript - jquery+on迭代循环我怎么知道点击了哪个元素
- xamarin.ios - xamarin 中带有 pushkit 的 callkit
- git - 将公共存储库中的更改合并到私有构建中
- c++ - 不存储字符串长度和其他此类值会使程序变慢吗?
- arrays - 将 awk 找到的每个事件存储到一个数组中