Question

I declared a global AppBar in App.xaml:

<Application.Resources>
    <shell:ApplicationBar x:Name="mAppBar_Favorites" Mode="Default" Opacity="1.0" IsMenuEnabled="True" IsVisible="True">
        <shell:ApplicationBarIconButton IconUri="/mAppData/feature.camera.png" Text="Kamera" Click="btnAppBar_OpenCamera_Click"/>
        <shell:ApplicationBarIconButton IconUri="/mAppData/edit.png" Text="Favoriten" Click="btnAppBar_EditFavorites_Click"/>
        <shell:ApplicationBarIconButton IconUri="/mAppData/refresh.png" Text="Refresh" Click="btnAppBar_ReloadMainPage_Click"/>
        <shell:ApplicationBarIconButton IconUri="/mAppData/sort.png" Text="Sortieren" Click="btnAppBar_SortOrder_Click"/>

        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="Einstellungen" Click="btnAppBar_ShowSettings_Click"/>
            <shell:ApplicationBarMenuItem Text="Über WhaGoO" Click="btnAppBar_About_Click"/>
        </shell:ApplicationBar.MenuItems>

    </shell:ApplicationBar>

</Application.Resources>

In the App.xaml.cs I defined the methods for the button click events like this:

    private void btnAppBar_SortOrder_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Sortierreihenfolge der Listeneinträge ändern...");
    }

On some pages I show the AppBar with this code in the page behind code:

    this.ApplicationBar = ((ApplicationBar)Application.Current.Resources["mAppBar_Favorites"]);

To that, everythings works fine. But now, on some pages I must have Access to the PivotControl of the page to decide the Uri to navigate to. This happens for example with the "refresh" button of the global AppBar:

    private void btnAppBar_ReloadMainPage_Click(object sender, EventArgs e)
    {
        int mPivotIndex = Convert.ToInt16(pvtMainPivot.SelectedIndex.ToString());
        if (mPivotIndex == 1)
        {
            // Tab "Umgebung" aktualisieren:
            MainPage.fGetSurroundings();
        }
    }

My app has a main page a PivotPage. Now I extend this with more pages and want not to "replicate" the AppBar to every new page.

How can I resolve these problems with navigation and accessing items on the pages?

Was it helpful?

Solution

For everyone, who´s interested in a solution:

App.xaml.cs:

private void btnAppBar_ReloadMainPage_Click(object sender, EventArgs e)
{
    // calling a method of the page:
    ((MainPage)App.RootFrame.Content).MyMethod();

    // accessing a value:
    var mValue = MainPage.myValue.toString();
}

MainPage.xaml.cs:

 public static int myValue;

 public void MyMethod()
 {
      // do stuff
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top