Close a non-button flyout?
Asked Answered
T

3

6

I'm making a 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 Flyout with

FlyoutBase.ShowAttachedFlyout(LayoutRoot);

But how to close it? I know the user can tap outside, but I also need to close the flyout when you click the restart o the cancel button...

Tratner answered 24/8, 2014 at 1:14 Comment(0)
M
6

Give it a Name

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

Then you can just Hide()

myFlyout.Hide();

FlyoutBase.Hide method

Marindamarinduque answered 24/8, 2014 at 1:38 Comment(0)
W
1
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.

Wrangler answered 24/8, 2014 at 7:43 Comment(0)
I
-1

You need to get it first. Then you can call Hide.

FlyoutBase.GetAttachedFlyout((FrameworkElement)LayoutRoot).Hide();
Insula answered 21/3, 2015 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.