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中进行操作提示的更多相关文章

  1. Day4:T1小技巧(类似于指针操作)T2搜索+小细节

    Day4:其中有很多小技巧get T1 一直没有听到过像这样的小技巧的略专业名词,有点类似于指针操作,之前有碰到过很多这样的题目 每次都是以不同的形式出现,但是感觉思想还是有点接近的吧(就比如某天有一 ...

  2. grep的用法,小技巧,模板中含有\t时:grep -P "^\t" file

    linux中grep和find的用法区别 本文章详细的介绍了关于在linux中的grep和find两个命令的用法介绍,以及后面总结了它们两年用法区别哦. 先我们来介绍一下关于grep用法和一些小注意事 ...

  3. Date小技巧:set相关操作及应用_获取当前月(季度/年)的最后一天

    set操作还是有不少的,具体见 http://www.w3school.com.cn/jsref/jsref_obj_date.asp, 今天我就只说 setFullYear, setMonth, s ...

  4. iOS开发小技巧 - label中的文字添加点击事件

    Label中的文字添加点击事件 GitHub地址:https://github.com/lyb5834/YBAttributeTextTapAction 以前老师讲过类似的功能,自己懒得回头看了,找了 ...

  5. 小技巧:webpack中@的配置和用法

    好家伙, 当我们要各种两个文件去引用别的文件时,一般这么写 import msg from '../../msg.js' 那么如果文件藏得很深,'../'会变得很多,不美观,也不直观 所以我们又又又可 ...

  6. iOS开发小技巧--iOS中设置applicationIconBadgeNumber遇到的问题

    iOS中设置applicationIconBadgeNumber 在iOS7中直接设置applicationIconBadgeNumber没有问题,但是在iOS8之后设置applicationIcon ...

  7. iOS开发小技巧--TableView中headerView的循环利用,以及自定义的headerView

    一.首先要搞清楚,tableView中有两种headerView,一个是tableHeaderView,另一个是headerView.前者就一个;后者根据session决定个数 headerView的 ...

  8. [小技巧]C#中如何为枚举类型添加描述方法

    背景 在我们的日常开发中,我们会经常使用枚举类型.有时我们只需要显示枚举的值或者枚举值对应名称, 但是在某些场景下,我们可能需要将枚举值显示为不同的字符串. 例: 当前我们有如下枚举Level pub ...

  9. [编程小技巧]Notepad++中如何实现文本对比功能?

    1.打开Notepad++插件中心   2.安装Compare   3.按提示重启Notepad++     4.点击Compare比较临近的两个文件       5. 取消比较     6 Comp ...

随机推荐

  1. Android文件选择器的实例分享

    本文给大家讲解下Android文件选择器的使用.实际上就是获取用户在SD卡中选择的文件或文件夹的路径,这很像C#中的OpenFileDialog控件. 此实例的实现过程很简单,这样可以让大家快速的熟悉 ...

  2. 也谈OpenFlow, SDN, NFV

    Copyright (2014) 郭龙仓. All Rights Reserved. OpenFlow 传统的网络环境中,仅仅有路由器/交换机之间的接口/协议是标准化的,可是在网络设备内部,数据平面和 ...

  3. mysqlpump 原理

    Oracle官方多线程逻辑备份工具 昨天Inside君写到MySQL 5.7.11版本发布,其中最有意义的部分在于官方修复了之前mysqlpump工具一致性备份的问题,使得mysqlpump工具在生产 ...

  4. Python学习 之 文件

    1.文件读写 python进行文件读写的函数是open或file file_handler=open(filename,,mode) (1)打开并读取文件 方式一:open() fo=open('/r ...

  5. 面试常备题---二叉树总结篇(zt)

    人生就像是一场长跑,有很多机会,但也得看我们是否能够及时抓牢,就像下面这样的代码: while(isRunning) { if(...){...} else if(...){...} ... else ...

  6. poj1753解题报告(枚举、组合数)

    POJ 1753,题目链接http://poj.org/problem?id=1753 题意: 有4*4的正方形,每个格子要么是黑色,要么是白色,当把一个格子的颜色改变(黑->白或者白-> ...

  7. Objective-C ,ios,iphone开发基础:NSDictionary(字典) 和 NSMutableDictionary

    NSDictionary(字典),NSDictionary类似于 .net中的parameter,l类似于java中的map. 通过唯一的key找到对应的值,一个key只能对应一个只,而多个key可以 ...

  8. [改善Java代码]小心switch带来的空值异常

    使用枚举定义常量时,会伴有大量的switch语句判断,目的是伪类每个枚举项解释其行为,例如: public class Client { public static void main(String[ ...

  9. VSX规划Package文件

    VSX是VS扩展,可以针对不同项目编写插件,虽然接触VSX的时间并不多,但是当了解VSX后深刻感受到VSX的魅力. VSX的材料比较少,配置文件也很繁琐,当初我也走了不少弯路. 这篇文章将帮助您更好的 ...

  10. 极其简单的使用基于gulp和sass前端工作流

    简单的记录自己如何在实际工作中使用gulp和sass的.我的原则是,小而美! gulp与sass介绍 gulp 什么是gulp?和Grunt一样,是一种任务管理工具:和Grunt又不一样,gulp是一 ...