Santosh Santosh - 2 months ago 45
C# Question

How to close WPF popup window?

I am developing project in WPF and I am facing a problem using a popup window in my project. I use popup control in my window as shown 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 i Create new page in wpf with textbox and button and set this page to popup frame show below:-

popupframe.Content=new SessionObjection();


Now i want to close popup window with page button. How i do...

Answer

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