小技巧: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 ...
随机推荐
- Android内存优化解决 资料和总结的经验分享
在前公司做一个图片处理的应用时, 项目交付的时候,客户的手机在运行应用的时候,一直在崩溃,而这个异常就是OutOfMemory的错误,简称为OOM, 搞得我们也是极其的崩溃,最后 ,我们是通过网上搜集 ...
- 使用Active MQ在.net和java系统之间通信
ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现 一.特性列表 ⒈ 多种语言和 ...
- .Net枚举类型小结
1.枚举类型的要点: (1)类型声明语法: enum 枚举名 (2)枚举体语法: a.成员名称 = 整数值,其他成员名称,或者其他成员与整数的表达式 b.成员之间需要用逗号隔开 (3)枚举可以继承的 ...
- NDK环境配置
1.下载安装插件:com.android.ide.eclipse.ndk_23.0.2.1259578.jar copy到E:\eclipse\adt-bundle-windows-x86- ...
- android144 360 快捷方式
package com.example; import android.net.Uri; import android.os.Bundle; import android.app.Activity; ...
- MyISAM表锁
MyISAM存储引擎只支持表锁,这也是MySQL开始几个版本中唯一支持的锁类型.随着应用对事务完整性和并发性 要求的不断提高,MySQL才开始开发基于事务的存储引擎,后来慢慢出现了支持页锁的BDB存储 ...
- spring源码分析之spring-web web模块分析
0 概述 spring-web的web模块是更高一层的抽象,它封装了快速开发spring-web需要的基础组件.其结构如下: 1. 初始化Initializer部分 1.1 Servlet3.0 的 ...
- SQL Insert语句数据以以unicode码存储 解决存储数据出现乱码的问题
写了个读取原始的文本数据导入数据库的工具 ,最后发现空中有几个值是乱码 例如 原始数据是 :Bjørn 存到数据库中是 Bj?rn 研究半天发现是一直以来忽略了一个标记‘N’ 2条 Insert 语句 ...
- 英文破折号(em dash)、连接号(en dash)与连字符(hyphen)的区别及各自用法是什么?
英文破折号(em dash).连接号(en dash)与连字符(hyphen)的区别及各自用法是什么?在科技写作中有何特点? 2 条评论 分享 按票数排序按时间排序 6 个回答 赞同85反对, ...
- Share_memory
共享内存是允许多个进程共享一块内存,由此来达到交换信息的进程通信机制:它很快没有中间介质,唯一的不足就是需要一定的同步机制控制多个进程对同一块内存的读/写,,它的原理如下: 每个共享内存段都有一个sh ...