Xamarin.Forms应用程序的操作栏中的按钮?
是否有一种Xamarin.Forms方法可以将按钮添加到操作栏/导航项(无需使用平台特定代码)?如果操作栏/导航指顶部的导航栏,则可以使用此方法:Xamarin.Forms应用程序的操作栏中的按钮?,xamarin.forms,Xamarin.forms,是否有一种Xamarin.Forms方法可以将按钮添加到操作栏/导航项(无需使用平台特定代码)?如果操作栏/导航指顶部的导航栏,则可以使用此方法: private void ShowToolbar() { if (Device.OS == TargetPlatform.iOS) { // move layout under the status bar this.Padding = new Thickness(0, 20, 0, 0); toolbarItem = ne
private void ShowToolbar()
{
if (Device.OS == TargetPlatform.iOS)
{
// move layout under the status bar
this.Padding = new Thickness(0, 20, 0, 0);
toolbarItem = new ToolbarItem("Sync", "sync_icon.png", () =>
{
//if (!response)
//{
// response = true;
SyncService();
//}
//else
// return;
}, 0, 0);
ToolbarItems.Add(toolbarItem);
}
if (Device.OS == TargetPlatform.Android)
{
toolbarItem = new ToolbarItem("Sync", "sync_icon.png", () =>
{
//if (!response)
//{
SyncService();
//}
//else
// return;
}, 0, 0);
ToolbarItems.Add(toolbarItem);
}
if (Device.OS == TargetPlatform.WinPhone)
{
toolbarItem = new ToolbarItem("Sync", "sync_icon.png", () =>
{
//if (!response)
//{
// response = true;
SyncService();
//}
//else
// return;
}, 0, 0);
ToolbarItems.Add(toolbarItem);
}
}
在MainPage.xaml中,可以添加以下代码
<ContentPage.ToolbarItems>
<ToolbarItem Text="Click Me!" Icon="iconName.png" Clicked="ToolbarItem_Clicked"/>
</ContentPage.ToolbarItems>
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
为了进行导航,App.xaml.cs中的构造函数应该包含以下代码
<ContentPage.ToolbarItems>
<ToolbarItem Text="Click Me!" Icon="iconName.png" Clicked="ToolbarItem_Clicked"/>
</ContentPage.ToolbarItems>
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}