How to close WPF popup?

I am developing a project in WPF and am encountering a problem using a popup in my project. I am using popup control in my window as below: -

<Popup HorizontalAlignment="Center" VerticalAlignment="Center" 
    AllowsTransparency="True" x:Name="popup" Placement="Center" 
    OpacityMask="#FFC86E6E" Closed="popup_Closed" >
    <Grid Height="auto" Width="auto" Margin="0" >
        <Grid.RowDefinitions>
            <RowDefinition Height="0.488*"/>
            <RowDefinition Height="0.512*"/>
        </Grid.RowDefinitions>

        <Frame x:Name="popupframe" Margin="0" Grid.Row="1"  />
        <Button Width="30" Height="30"  HorizontalAlignment="Right" 
                            Margin="0,0,10,-50" VerticalAlignment="Center" 
                            BorderThickness="0" BorderBrush="{x:Null}" 
                            ClickMode="Press" Click="Button_Click" 
                            Foreground="{x:Null}">
            <Button.Background>
                <ImageBrush ImageSource="Image/1329666144_button_cancel.png" Stretch="UniformToFill"/>
            </Button.Background>
        </Button>
            </Grid>
</Popup>

Now create a new page in wpf using the text box and button and set this page to the drop-down menu below: -

popupframe.Content=new SessionObjection();

Now I want to close the popup with the page button. Like me...

+5
source share
3 answers

You can close the popup by setting the IsOpen property to false.

+8
source

you can try with

private void btnClosePopup_Click(object sender, RoutedEventArgs e)
        {
            popup.IsOpen = false;
        }
+4
source

XAML, ( "" ):

    <Button Name="CloseThisPopUp" VerticalAlignment="Top" HorizontalAlignment="Right" Content="X">
                                        <Button.Triggers>
                                            <EventTrigger RoutedEvent="Button.Click">
                                                <EventTrigger.Actions>
                                                    <BeginStoryboard>
                                                        <Storyboard>
                                                            <BooleanAnimationUsingKeyFrames Storyboard.TargetName="CloseThisPopUp" Storyboard.TargetProperty="IsOpen">
                                                                <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False" />
                                                            </BooleanAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </EventTrigger.Actions>
                                            </EventTrigger>
                                        </Button.Triggers>
                                    </Button>

, , IsOpen "True".

0

All Articles