【问题标题】:How to close the pop up window when I click outside window in wpf in mahapps?当我在mahapps中单击wpf中的外部窗口时如何关闭弹出窗口?
【发布时间】:2015-05-18 08:28:27
【问题描述】:

我的 WPF 应用程序中有一个 Flyoout 弹出窗口和测试窗口。我需要的是,当我在 Flyout 之外单击时需要关闭窗口。我将 Panel.Zindex 设置为可见顶部。我尝试了一个运行良好的代码。但它不知道我是在 Flyout 内部还是在 Flyout 窗口外部单击。每当我在主屏幕内单击时,它就会关闭。!

这是我的 xaml 代码:

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>

如果我在测试窗口屏幕中,我可以将 Isopen 属性设置为 true 这个 Flyout。 如果我在任何其他窗口之外单击,如何关闭它?

任何帮助都会非常感谢..提前谢谢..

【问题讨论】:

  • 检查 metro:Flyout 是否有 IsLightDismissEnabled 属性。如果是,则将其设置为 true。或者,如果您在控制经典弹出窗口中将此属性设置为 true。
  • 我没有这个属性。
  • 尝试检查是否存在属性IsPinned

标签: wpf xaml mahapps.metro flyout


【解决方案1】:

在弹出窗口中将 isPinned 属性设置为 false,如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 2021-11-21
    • 2020-03-07
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多