Search code examples
c#windows-store-appswinrt-xamlappbar

Why does there seem to be no "Opened" event for a WinRT XAML BottomAppBar?


I want to respond to the opening of a bottom app bar in my Windows Store App. Elsewhere, I was advised that there is, indeed, and "Opened" event for it, but this:

<Page.BottomAppBar x:Name="bottomAppBar" Opened="bottomAppBar_Opened" >

...results in a red (unrecognized) "Opened", and the method name I entered does not generate a corresponding handler in the code-behind.

I want to be able to do something like this:

private void bottomAppBar_Opened(object sender, object e)
{
    appbarbtnOpenPhotosets.Enabled = PhotraxSQLiteUtils.DatabaseContainsRecords();
    appbarbtnCre8FilteredPhotoset.Enabled = appbarbtnOpenPhotosets.IsEnabled; // or call the 
        query again, if necessary
    appbarbtnClearMap.Enabled = MapHasMarkers();
}

...but what event can I use, or how can I hook into the opening of the appbar?

And actually, giving the Page's BottomAppBar a name was not allowed, either.


Solution

  • Page.TopAppBar is an (attached) property, so you are trying to set a property on a property assignment. Moreover, as you see here, the child of Page.TopAppBar must be an AppBar object.

    So, you should do the following

      <Page.TopAppBar>
          <AppBar Opened="...">
              <!-- Here the AppBar's content -->
          </AppBar>
      </Page.TopAppBar>