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无法生成R文件的终极解决办法

    R文件如果在clean项目(Project—>Clean)和 Fix Project Properties(如下图):   如果在第一步无法解决的的时候,那可能原因就是资源文件调用的错误,比如资 ...

  2. aspose.cells 模版

    aspose.cells 模版  http://www.cnblogs.com/whitewolf/archive/2011/03/21/Aspose_Cells_Template1.html

  3. sizeof求字节以及与strlen的区别

    例子一: /* *根据以下条件进行计算: *1. 结构体的大小等于结构体内最大成员大小的整数倍 *2. 结构体内的成员的首地址相对于结构体首地址的偏移量是其类型大小的整数倍,比如说double型成员相 ...

  4. 高级I/O之记录锁

    若两个人同时编辑一个文件,其后果将如何呢?在很多UNIX系统中,该文件的最后状态取决于写该文件的最后一个进程.但是对于有些应用程序(例如数据库),进程有时需要确保它正在单独写一个文件.为了向进程提供这 ...

  5. Windows 10正式版官方原版ISO镜像下载

    [微软官方]下载地址1:官方下载工具(32-位系统版本)官方下载工具(64-位系统版本) [MSDN]下载地址2:cn_windows_10_multiple_editions_x64_dvd_684 ...

  6. 随机森林实现 MATLAB

    matlab 中随机森林工具箱的下载地址: http://code.google.com/p/randomforest-matlab/downloads/detail?name=Windows-Pre ...

  7. uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型(转)

    在nesc的代码中,你会看到很多你不认识的数据类型,比如uint8_t等.咋一看, 好像是个新的数据类型,不过C语言(nesc是C的扩展)里面好像没有这种数据类型啊!怎么又是u又是_t的?很多人有这样 ...

  8. MPEG简介 + 如何计算CBR 和VBR的MP3的播放时间

    1. 声明本文所写内容,多数整理自互联网,版权归原作者所有笔者知识有限,文中难免有误,欢迎批评指正,admin (at) crifan.com觉得此文对你有帮助,想要发邮件来感谢的,也欢迎哈,^_^欢 ...

  9. 修改MySQL的时区

    修改MySQL的时区,涉及参数time_zone 首先需要查看mysql的当前时区,用time_zone参数 ? 1 2 3 4 5 6 7 8 9 [html] mysql> show var ...

  10. Debian 7 64位安装 wine

    一.安装 1. # apt-get install wine 安装完后在终端里运行wine: # wine 会弹出一个对话框: This is the wine64-bin helper packag ...