2015-04-06 12 views

risposta

10

Se dall'azione bar/navigazione si intende la barra di navigazione in alto è possibile utilizzare questo metodo:

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); 
    } 
} 
0

In MainPage.xaml, si può aggiungere il seguente codice.

<ContentPage.ToolbarItems> 
    <ToolbarItem Text="Click Me!" Icon="iconName.png" Clicked="ToolbarItem_Clicked"/> 
</ContentPage.ToolbarItems> 

Ora, nel file MainPage.xaml.cs, deve essere aggiunto il gestore di clic.

public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private async void ToolbarItem_Clicked(object sender, EventArgs e) 
    { 
     await Navigation.PushAsync(new NewPage()); 
    } 
} 

per la navigazione a verificarsi, il costruttore in App.xaml.cs dovrebbe contenere codice seguente.

public App() 
    { 
     InitializeComponent(); 
     MainPage = new NavigationPage(new MainPage()); 
    } 
Problemi correlati