Close popup without button?

I make Flyout attached to the LayoutRoot grid.

<Page.Resources> <Flyout x:Key="WinningPopup"> <StackPanel Margin="50,10"> <TextBlock x:Uid="Flyout_VictoryTitle" Text="Victory!" Style="{StaticResource MessageDialogTitleStyle}" Margin="0,0,0,15"/> <TextBlock x:Name="Flyout_VictoryDescription" x:Uid="Flyout_VictoryDescription" Text="Congratulations!&#x0a;Score: " Style="{StaticResource MessageDialogContentStyle}" /> <StackPanel Orientation="Horizontal"> <Button x:Name="btnRestart" x:Uid="btnRestart" Click="btnRestart_Click" Content="[Restart]" Margin="10"/> <Button x:Name="btnCancel" x:Uid="btnCancel" Click="btnCancel_Click" Content="[Cancel]" Margin="10"/> </StackPanel> </StackPanel> </Flyout> </Page.Resources> <Grid x:Name="LayoutRoot" FlyoutBase.AttachedFlyout="{StaticResource WinningPopup}"> ... 

I open this file with

 FlyoutBase.ShowAttachedFlyout(LayoutRoot); 

But how to close it? I know that the user can go outside, but I also need to close the popup when you press the restart o cancel button ...

+5
source share
3 answers

Give him a name

 <Page.Resources> <Flyout x:Name="myFlyout" x:Key="WinningPopup"> // ...... </Flyout> </Page.Resources> 

Then you can just Hide ()

 myFlyout.Hide(); 

FlyoutBase.Hide Method

+6
source
 public void btnRestart_Click(object sender, RoutedEventArgs) { ((((sender as Button).Parent as StackPanel).Parent as StackPanel).Parent as Flyout).Hide(); } 

Very ugly, but should work.

0
source

You need to do this first. Then you can call Hide .

 FlyoutBase.GetAttachedFlyout((FrameworkElement)LayoutRoot).Hide(); 
-1
source

Source: https://habr.com/ru/post/1201003/


All Articles