简体   繁体   中英

How should AppBars be hidden after button click?

The Windows Store app that I am working on has two AppBars on the main page. One on top for navigation and another below for commands.

Obviously, I want the AppBars to close after the new command button is clicked. The following code works, but it seems rather ungainly:

private void appbarNew_Click(object sender, RoutedEventArgs e)
{
    App.viewModel.newModel();

    this.TopAppBar.IsOpen = false;
    this.BottomAppBar.IsOpen = false;
}

I assumed that the AppBars would be closed automatically or at least there'd be some sort of "handled" boolean in the event object that could be used to accomplish this. What is the proper solution here?

You can control with this code. You can check and also you can set IsOpen with bool.

Tal Malaki's solution just hide or visible it, this code is the solution what you're looking for

ApplicationBarName.IsOpen = false / true;

Give you AppButton a name like AppBtn. Then try this on the click event:

AppBtn.Visiblity=Visibilty.Hidden;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM