var tileMore = new Tile
{
Height = ,
Width = ,
Background = new SolidColorBrush(Color.FromRgb(, , )),
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 * ,
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(, , );
timerCloseRecentPopup.Tag = popup;
timerCloseRecentPopup.Tick += closePopup;
}
timerCloseRecentPopup.Stop();
timerCloseRecentPopup.Start();
}; popup.MouseLeave += (s, e) =>
{
if(timerCloseRecentPopup == null)
{
timerCloseRecentPopup = new DispatcherTimer();
timerCloseRecentPopup.Interval = new TimeSpan(, , );
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自动关闭的更多相关文章

  1. WPF Popup 控件导致被遮挡内容不刷新的原因

    WPF Popup 控件导致被遮挡内容不刷新的原因 周银辉 今天在写一个WPF控件时用到了Popup控件,很郁闷的情况是:当popup关闭时,原来被popup挡住的界面部分不刷新,非要手动刷新一下(比 ...

  2. WPF Popup 置顶问题

    原文 WPF Popup 置顶问题 问题: 使用wpf的popup,当在popup中弹出MessageBox或者打开对话框的时候,popup总是置顶,并遮住MessageBox或对话框. 解决: 写如 ...

  3. WPF Popup全屏 弹出方法。解决只显示75%的问题。

    WPF Popup全屏 弹出方法.解决只显示75%的问题.   WPF 中 Popup 有一个特点.当Popup的高度超过屏幕的75%的时候,只显示75%的高度. 如下代码: <Window x ...

  4. 自定义WPF Popup控件

    解决问题 1.WPF Popup 不随着 Window 一起移动的问题 2.WPF Popup 总是显示在最前面 引用命名空间 xmlns:ctrl="clr-namespace:Micro ...

  5. wpf Popup Win8.0 bug HorizontalOffset 弹出位置偏移

    问题描述参考 wpf 客户端[JDAgent桌面助手]开发详解(四) popup控件的win8.0的bug 当开发完程序后,我们在多操作系统测试时候发现:win8.0  系统中 popup 弹出的位置 ...

  6. WPF popup被截断的原因和修改方法

    原因:wpf里 popup不能超过屏幕75%的面积,不知道为什么要这么设置? 修改方法: private void SetPopupScreen() { Rect rtWnd = , , gridMa ...

  7. WPF Popup 右下角提示框 定时消失 ,以及任意位置定位

    ------------恢复内容开始------------ 好久没写WPF的博客了,其实有很多心得要总结下,但是懒..... 今天工作需要,需要实现一个 1 右下角的提示窗口,然后过三五秒自动消失这 ...

  8. WPF popup置顶

    在程序写一个popup发现他会在置顶,在网上找了两大神代码http://www.cnblogs.com/Leaco/p/3164394.html http://blog.csdn.net/baijin ...

  9. WPF popup控件的使用

    <Window x:Class="WPFPopup.RuntimePopup"     xmlns="http://schemas.microsoft.com/wi ...

随机推荐

  1. Confluence 6 在升级之前

    在这个指南中,我们将会与你一同对最新的 Confluence 站点在 Windows 或者 Linux 平台进行安装和更新. 如果你的 Confluence 安装实例是当前的许可证的话,那么对 Con ...

  2. windows 下 修改jmeter ServerAgent端口

    from:https://blog.csdn.net/wanglha/article/details/51281462 如果想修改UDP和TCP的端口该如何做呢,可以采用如下的方式: CMD命令进入S ...

  3. C++标准模板库(STL)之Queue

    1.Queue的常用用法 queue:队列,实现的一个先进先出的容器. 1.1.queue的定义 使用queue,首先要加头文件#include<queue>和using namespac ...

  4. QT中添加工具条QToolBar

    项目用的QT5.3,设计师中没有直接拖工具条的控件,那要怎么加工具条呢? 其实.ui文件是xml类型的文本文件,用uedit或记事本打开,找到之前有的工具条段落,复制粘贴一个,保存,再在vs中用设计师 ...

  5. OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用 问题处理

    OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用 问题处理如下: 解决方法一:更换连接方式 config 文件配置: <add name="MASTER_DB&q ...

  6. SQL基本介绍

    SQL学习资料来源:http://www.w3school.com.cn/sql/index.asp SQL 是用于访问和处理数据库的标准的计算机语言. 什么是 SQL?SQL 指结构化查询语言SQL ...

  7. python requests + xpath 获取分页详情页数据存入到txt文件中

    直接代码,如有不懂请加群讨论# *-* coding:utf-8 *-* #import jsonimport requestsimport pytesseractimport timeimport ...

  8. PDF 补丁丁 0.6.0.3340 版发布(修复提取图片的问题)

    新的版本修复了两个导致提取图片颜色异常的问题.

  9. pip更新

    python -m ** install -U **

  10. Unity实现用户条款弹窗及登录

    首先来看效果图... 1.先编辑页面 1)新建登录按钮,更名为Login 2)新建toggle,新建方式如下图 调整toggle的大小和位置到适当的范围. 3)新建同意用户条款按钮,步骤为新建UI-& ...