小技巧:SystemTray中进行操作提示
SystemTray中进行操作提示在wp中应用比较广泛,截图如下。

实现方法也十分简单
1、xaml代码中写入:
shell:SystemTray.IsVisible="True"
shell:SystemTray.Opacity="0"
2、C#代码中写入:
private ProgressIndicator _progressIndicator = new ProgressIndicator(); private void ShowProgress(String message)
{
_progressIndicator.Text = message;
_progressIndicator.IsVisible = true;
_progressIndicator.IsIndeterminate = true;
SystemTray.SetProgressIndicator(this, _progressIndicator);
} private void HideProgress()
{
_progressIndicator.IsVisible = false;
SystemTray.SetProgressIndicator(this, _progressIndicator);
}
在需要显示提示文字的地方调用ShowProgress(String message)方法。隐藏的地方调用HideProgress方法即可。
由于SystemTray.SetProgressIndicator(this, _progressIndicator);中this必须是 页面 的实例对象,为此在usercontrol控件想掉用此方法就必须找到usercontrol所在的页面。
写一个TreeExtensions的静态类用于获取页面
public static class TreeExtensions
{
public static IEnumerable<T> Ancestors<T>(this DependencyObject item)
{
return item.Ancestors().Where(i => i is T).Cast<T>();
} /// <summary>
/// 返回可视树中所有父代元素集合(不包括本身)
/// </summary>
public static IEnumerable<DependencyObject> Ancestors(this DependencyObject item)
{
var parent = item.ParentEx();
while (parent != null)
{
yield return parent;
parent = parent.ParentEx();
}
}
/// <returns></returns>
public static DependencyObject ParentEx(this DependencyObject item)
{
return VisualTreeHelper.GetParent(item);
}
}
获取页面代码:
var phonePage = this.Ancestors<PhoneApplicationPage>().FirstOrDefault();
同时using TreeExtensions类所在的命名空间。
把this 替换成phonePage即可。
可在任何地方调用的showtip代码段
当前页面通过PhoneApplicationPage page = (Application.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage;获取
public void showtip(string tip)
{
PhoneApplicationPage page = (Application.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage;
if (_progressIndicator == null)
{
_progressIndicator = new ProgressIndicator();
}
_progressIndicator.Text = tip;
_progressIndicator.IsVisible = true;
_progressIndicator.IsIndeterminate = true;
SystemTray.SetProgressIndicator(page, _progressIndicator);
}
private ProgressIndicator _progressIndicator; public void HideProgress()
{
if (_progressIndicator != null)
{
PhoneApplicationPage page = (Application.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage;
_progressIndicator.IsVisible = false;
SystemTray.SetProgressIndicator(page, _progressIndicator);
}
}
示例:http://files.cnblogs.com/fatlin/TestShowTip.rar
小技巧:SystemTray中进行操作提示的更多相关文章
- Day4:T1小技巧(类似于指针操作)T2搜索+小细节
Day4:其中有很多小技巧get T1 一直没有听到过像这样的小技巧的略专业名词,有点类似于指针操作,之前有碰到过很多这样的题目 每次都是以不同的形式出现,但是感觉思想还是有点接近的吧(就比如某天有一 ...
- grep的用法,小技巧,模板中含有\t时:grep -P "^\t" file
linux中grep和find的用法区别 本文章详细的介绍了关于在linux中的grep和find两个命令的用法介绍,以及后面总结了它们两年用法区别哦. 先我们来介绍一下关于grep用法和一些小注意事 ...
- Date小技巧:set相关操作及应用_获取当前月(季度/年)的最后一天
set操作还是有不少的,具体见 http://www.w3school.com.cn/jsref/jsref_obj_date.asp, 今天我就只说 setFullYear, setMonth, s ...
- iOS开发小技巧 - label中的文字添加点击事件
Label中的文字添加点击事件 GitHub地址:https://github.com/lyb5834/YBAttributeTextTapAction 以前老师讲过类似的功能,自己懒得回头看了,找了 ...
- 小技巧:webpack中@的配置和用法
好家伙, 当我们要各种两个文件去引用别的文件时,一般这么写 import msg from '../../msg.js' 那么如果文件藏得很深,'../'会变得很多,不美观,也不直观 所以我们又又又可 ...
- iOS开发小技巧--iOS中设置applicationIconBadgeNumber遇到的问题
iOS中设置applicationIconBadgeNumber 在iOS7中直接设置applicationIconBadgeNumber没有问题,但是在iOS8之后设置applicationIcon ...
- iOS开发小技巧--TableView中headerView的循环利用,以及自定义的headerView
一.首先要搞清楚,tableView中有两种headerView,一个是tableHeaderView,另一个是headerView.前者就一个;后者根据session决定个数 headerView的 ...
- [小技巧]C#中如何为枚举类型添加描述方法
背景 在我们的日常开发中,我们会经常使用枚举类型.有时我们只需要显示枚举的值或者枚举值对应名称, 但是在某些场景下,我们可能需要将枚举值显示为不同的字符串. 例: 当前我们有如下枚举Level pub ...
- [编程小技巧]Notepad++中如何实现文本对比功能?
1.打开Notepad++插件中心 2.安装Compare 3.按提示重启Notepad++ 4.点击Compare比较临近的两个文件 5. 取消比较 6 Comp ...
随机推荐
- 发布站点到远程FTP根目录
第一步:修改 phpcms/modules/admin/templates/site_add.tpl.php 找到 <legend><?php echo L('release_poi ...
- Swift3.0语法变化
写在前面 首先和大家分享一下学习新语法的技巧:用Xcode8打开自己的Swift2.3的项目,选择Edit->Convert->To Current Swift Syntax- 让Xcod ...
- mysql 面试
数据库的重要性是所有技术里最核心最需要掌握的(理解原理,并且被面试时能清晰的表达出来),直接决定运维人员薪水的高低! 所有题都要给出专业的解答方案,不是很水的那种泛泛的解答. 面试题001:什么是My ...
- leetcode -- Search for a Range (TODO)
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- Python学习 之 爬虫
目标:下载贴吧或空间中所有图片 步骤:(1)获取页面代码 (2)获取图片URL,下载图片 代码如下: #!/usr/bin/python import re import urllib def get ...
- 1043. Is It a Binary Search Tree (25)
the problem is from pat,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1043 and the ...
- Discuz x 默认模板文件目录说明
template/default/common模板公共文件夹,全局相关 |--block_forumtree.htm 树形论坛版块分支 js 文件 |--block_thread.htm 特殊主题的风 ...
- 网口扫盲三:以太网芯片MAC和PHY的关系
转载:http://www.cnblogs.com/jason-lu/articles/3195473.html 问:如何实现单片以太网微控制器? 答:诀窍是将微控制器.以太网媒体接入控制器(MA ...
- python 学习笔记re
在学习python的过程中很多时候都需要用到re(正则),因为我也不是开发所以呢只是简单说一下经常需要用到的东西. 在工作中经常用到的主要是三个函数:1.math 2.search 3.sub ...
- 小白日记26:kali渗透测试之提权(六)--收集敏感信息,隐藏痕迹
提权后操作 提权之后,要收集目标系统的重要信息LINUX /etc/resolv.conf #查看DNS配置,是否可以进行DNS篡改或劫持 /etc/passwd #存放账 ...