WPF popup自动关闭

摘要:
pop.IsMouseOver){if(tileMore!=null){if(!
          var tileMore = new Tile
                    {
                        Height = 40,
                        Width = 85,
                        Background = new SolidColorBrush(Color.FromRgb(120, 240, 120)),
                        Title = "更多...",
                    };
                tileMore.SetResourceReference(FrameworkElement.StyleProperty, "KentTile");

                Popup popup = new Popup
                    {
                        //StaysOpen = false,
                        PopupAnimation = PopupAnimation.Slide,
                        PlacementTarget = tileMore,
                        Placement = PlacementMode.Bottom,
                        AllowsTransparency = true
                    };
                //pop里面生成的内容,本例是StackPannel中包括一个textbox
                WrapPanel stackPanel = new WrapPanel
                    {
                        Width = tileMore.Width * 5,
                        Background = Brushes.Transparent
                    };
                stackPanel.Children.Add(/*sth to show*/);
                popup.Child = stackPanel;

                tileMore.MouseEnter += (sender, e) =>
                    {
                        popup.IsOpen = true;
                    };

                tileMore.MouseLeave += (s, e) =>
                {
                    if (timerCloseRecentPopup == null)
                    {
                        timerCloseRecentPopup = new DispatcherTimer();
                        timerCloseRecentPopup.Interval = new TimeSpan(0, 0, 1);
                        timerCloseRecentPopup.Tag = popup;
                        timerCloseRecentPopup.Tick += closePopup;
                    }
                    timerCloseRecentPopup.Stop();
                    timerCloseRecentPopup.Start();
                };

                popup.MouseLeave += (s, e) =>
                    {
                        if(timerCloseRecentPopup == null)
                        {
                            timerCloseRecentPopup = new DispatcherTimer();
                            timerCloseRecentPopup.Interval = new TimeSpan(0, 0, 1);
                            timerCloseRecentPopup.Tag = popup;
                            timerCloseRecentPopup.Tick += closePopup;
                        }
                        timerCloseRecentPopup.Stop();
                        timerCloseRecentPopup.Start();
                    };

 

     /// <summary>
        /// 定时关闭 更多 popup窗口
        /// </summary>
        private DispatcherTimer timerCloseRecentPopup;
        private void closePopup(object state,EventArgs e)
        {
            Popup pop = timerCloseRecentPopup.Tag as Popup;
            if(pop == null)
            {
                //todo timer里面的Assert没有对话框出来
                Debug.Assert(true,"pop==null");
                return;
            }

            Tile tileMore = pop.PlacementTarget as Tile;

            if (!pop.IsMouseOver )
            {
                if(tileMore != null)
                {
                    if(!tileMore.IsMouseOver)
                    {
                        pop.IsOpen = false;
                        timerCloseRecentPopup.Stop();
                    }

                }
                else
                {
                    pop.IsOpen = false;
                    timerCloseRecentPopup.Stop();
                }
            }
            
        }

免责声明:文章转载自《WPF popup自动关闭》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇安卓自定义控件最小环——Floyd变种算法(C++)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

vs下调试程序时,把信息打印到输出窗口

重印:https://blog.csdn.net/cwj066/article/details/82423627 https://stackoverflow.com/questions/20508086/getting-rid-of-atltracegeneral-category-shown-in-atltrace-output方法1:编写一个变量参数函数...

CAD转DXF怎么转换?教你三种转换方法

2.进入到CAD版本转换的界面中后,在选择“点击选择文件”,在跳转出的“打开”界面中打开需要转换的CAD图纸。...

Qt中使用定时器(可使用QObject::timerEvent定时执行,QTimer::singleShot可只触发一次)

在Qt中使用定时器有两种方法,一种是使用QObiect类的定时器;一种是使用QTimer类。当定时器触发时,应用程序会发送一个QTimerEvent。与定时器相关的成员函数有:startTimer()、timeEvent()、killTimer()。virtualvoidQObject::timerEvent;虚函数timerEvent()被重载来实现用户的...

Ubuntu 下查看CPU 信息命令

看看带有“处理器”一词的行数,即逻辑CPU的数量。因此,您可以在cmd下输入以下命令:cat/proc/cpuinfo|greproprocessor|wc-l因此,C++程序自然会想到使用strstr函数来查找processor关键字的出现次数。...

微软新一代输入法框架 TSF

目前,市场上的非微软中文输入法基本上只实现IMM框架。自Windows XP开始以来,Windows提供了一个基于COM的新输入框架TSF。但是,Windows Vista和Windows 7用户也可以使用各种基于IMM的输入方法,因为Windows提供了一个组件来将所有TSF请求转换为IMM API。很可能,因为Win8下的许多Imm函数无法使用。)根据微...

ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序

使用C#生成应用程序以及读取和写入dbfs时,打开方法error[IM002][Microsoft][ODBC驱动程序管理器]中发生错误。找不到数据源名称,也未指定默认驱动程序。这个程序以前使用得很好。升级和修改后,在测试中发现了问题。为了追踪来源,我曾经是一个32位操作系统。现在我安装了一个win764位操作系统。从控制面板到管理工具再到ODBC驱动程序,...