question

Lettuce-3031 avatar image
0 Votes"
Lettuce-3031 asked YanGu-MSFT answered

Is there a way to prevent a flyout from hiding in UWP?

Hello,

On my page I have a command bar, in it I have an AppBarButton and in it I have a flyout which is something like this:

 <AppBarButton x:Name="Reports" Icon="Page2" Label="Reports">
     <AppBarButton.Flyout>
         <MenuFlyout x:Name="ReportFlyout">
             (more stuff here)
             <ToggleMenuFlyoutItem  Name="ToggleStuff" Text="ToggleStuff" Click="ToggleStuff_Click" />
         </MenuFlyout>
     </AppBarButton.Flyout>
 </AppBarButton>

I want the user to be able to click the ToggleMenuFlyoutItem without the flyout hiding. Is this possible?


windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YanGu-MSFT avatar image
1 Vote"
YanGu-MSFT answered

Hello,

Welcome to Microsoft Q&A.

You could cancel the closing of the flyout in its Closing event handler to prevent a flyout from being hidden when clicked.

Please check the following code as a sample:

MainPage.xaml

 <AppBarButton x:Name="Reports" Icon="Page2" Label="Reports">
     <AppBarButton.Flyout>
         <MenuFlyout x:Name="ReportFlyout" Closing="ReportFlyout_Closing">
             <ToggleMenuFlyoutItem Name="TogleStuff" Click="TogleStuff_Click" Text="click me"/>
         </MenuFlyout>
     </AppBarButton.Flyout>
 </AppBarButton>

MainPage.xaml.cs

 private bool flag = false;  //The flag is used to indicate if the TogleStuff is clicked.
    
 private void TogleStuff_Click(object sender, RoutedEventArgs e)
 {
     flag = true;
     //Do other things.
 }
    
 private void ReportFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs args)
 {
     if(flag==true)
     {
         args.Cancel = true;  //If the TogleStuff is clicked, cancel the closing process.
     }
     flag = false;
 }


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.







5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.