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. OpenBUGS抽样数据基本操作

    新建两个文件 第一个文件写操作程序,第二个文件写数据数量,类似于下图 鼠标聚焦在第一个文件中,点击工具栏的Model,选择Specification,然后点击check Moel,会有弹框出现 点击确 ...

  2. 102. Binary Tree Level Order Traversal二叉树层序遍历

    网址:https://leetcode.com/problems/binary-tree-level-order-traversal/ 参考:https://www.cnblogs.com/grand ...

  3. Git版本库管理

    Step 1 查看哪些历史提交过文件占用空间较大 使用以下命令可以查看占用空间最多的五个文件: git rev-list --objects --all | grep "$(git veri ...

  4. 解决MySQL数据库连接太多,多数Sleep

    1.查看当前所有连接的详细资料: mysqladmin -uroot -proot processlist 客户端使用: show full processlist 2.只查看当前连接数(Thread ...

  5. mysql权限参考

    mysql日常管理和应用工作中,大家经常会涉及到授权问题,下面,我们就列举下权限相关的参考. 1.管理权限(Administrative Privileges) Privilege Name      ...

  6. Monkey 生成报告方法

    Monkey 命令简介 Monkey 是 SDK 中附带的一个小工具,用来进行压力测试.进行压力测试之前,首先要进行安装 SDK ,并配置环境变量: 1.安装 Java JDK 并配置环境变量(计算机 ...

  7. 基于thinkphp的后台管理系统模板快速搭建

    当我们在搭建网站的时候,后端开发人员在编写后台的管理系统的时候,往往会因为缺少一个合适的后台管理系统的模板,而必须去重新编写一个,这几天由于工作上的安排,需要去研究一下thinkcmf的后台管理系统, ...

  8. java FileUtil工具类

    网上的版本太多,整合了一下适合自己用的工具类,包括读取.保存.拷贝文件等. public class FileUtil { /** * 私有构造方法,防止类的实例化,因为工具类不需要实例化. */ p ...

  9. sqlserver数据库方面的排序四大王

    --1. row_number 用法 这个函数的功能是为查询出来的每一行记录生成一个序号select row_number() over(order by stuid) as row_number,* ...

  10. apk文件二维码微信无法识别 APP在微信中二维码扫描无法下载的解决方案

    现在微信分享的功能很多,从分享的链接下载apk安卓包是很正常的,但是微信不让下载apk包,只能通过浏览器来下载,但是这要给用户一个提示吧,不然用户不知道 下面我们来实现,引导用户通过浏览器来下载apk ...