Raj De Inno
Raj De Inno

Reputation: 1224

How to close the pop up window when I click outside window in wpf in mahapps?

I have a Flyoout popup window and Test window in my WPF application. What I need is, I need to close the window when I click outside of the Flyout. I set Panel.Zindex to visible top. I have tried a code which is working fine. But it doesn't know whether I click inside the Flyout or outside the flyout window. Its closing when ever i click inside main screen.!

Here is my xaml code:

xmlns:metro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

 <metro:Flyout x:Name="flyOutControl" IsOpen="False" Background="#5D7BA5"      Foreground="White"
                                  Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Grid.ColumnSpan="2" Panel.ZIndex="50"
                                  Width="400" Height="auto">


                            <TreeView x:Name="treeviewBreadcrumb" Width="350"
                                      HorizontalAlignment="Left" FontSize="20"
                                      Background="Transparent" Foreground="White"                                 
                                    VerticalAlignment="Top">

                                <TreeView.ItemContainerStyle>
                                    <Style TargetType="{x:Type TreeViewItem}">
                                        <Setter Property="IsExpanded" Value="True"/>                                            
                                        <Setter Property="Margin" Value="5"/>
                                        <Setter Property="Foreground" Value="White"/>                                            
                                    </Style>
                                </TreeView.ItemContainerStyle>                                    

                            </TreeView>

                    </metro:Flyout>

If i am in Test window screen, I can set a Isopen property to true this Flyout. how can i close this if i click outside of any other window?

Any help would be really appriciated.. Thanks in advance..

Upvotes: 1

Views: 1564

Answers (1)

QuanNH
QuanNH

Reputation: 71

Set isPinned property to false on your flyout like so:

<metro:Flyout IsPinned="False"></metro:Flyout>

Upvotes: 7

Related Questions