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. java中的正则操作总结

    http://www.cnblogs.com/nerxious/archive/2013/01/03/2842910.html 正则表达式在处理字符串的效率上是相当高的 关于正则表达式的使用,更多的是 ...

  2. string和stringbuilder的解剖

    String和StringBuilder的深入解析   前言:本文出发点是我们开发的过程中是否真正的理解stringbuilder的使用,string字符串操作的是如何实现(哈希表),stringbu ...

  3. [Javascript] Manipulate the DOM with the classList API

    Learn how to add, remove and test for CSS classes using the classList API. It's more powerful than u ...

  4. 随意一条查询sql转换为查询结果集相应的数目

    原思路: 像括号配对一样,假设遇见select 就入栈,假设遇见from就出栈,直到栈为空,取得此时的位置.进行字符串截取. 实现方法:遇见字符s而且连续后5个字符elect 就+1,遇见字符f而且连 ...

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

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

  6. SparkGraphXTest.scala

    /** * Created by root on 9/8/15. */ import org.apache.spark._ import org.apache.spark.graphx._ impor ...

  7. Linux命令行技巧

    Linux命令行技巧 命令 描述 • apropos whatis 显示和word相关的命令. 参见线程安全 • man -t man | ps2pdf - > man.pdf 生成一个PDF格 ...

  8. LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。

    var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...

  9. ASP.NET MVC 4 如何避免数据库被自动创建或自动迁移

    保哥说要想避免数据库被自动创建或自动迁移,可以在Global.asax文件里的Application_Start方法中加入: System.Data.Entity.Database.SetInitia ...

  10. Oracle 中记录用户登录信息

    我们可以使用 Oracle Audit 函数来记录用户登录信息,但是如果开放了 Audit 函数将会使 Oracle 性能下降,甚至导致 Oracle 崩溃.那我们如何才能记录用户登录信息呢?其实我们 ...