java systemtray 乱码_小技巧:SystemTray中进行操作提示

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

00812459cf5506dd4f13027d505ff4ee.png

实现方法也十分简单

1、xaml代码中写入:

shell:SystemTray.IsVisible="True"

shell:SystemTray.Opacity="0"

2、C#代码中写入:

private ProgressIndicator _progressIndicator = newProgressIndicator();private voidShowProgress(String message)

{

_progressIndicator.Text=message;

_progressIndicator.IsVisible= true;

_progressIndicator.IsIndeterminate= true;

SystemTray.SetProgressIndicator(this, _progressIndicator);

}private voidHideProgress()

{

_progressIndicator.IsVisible= false;

SystemTray.SetProgressIndicator(this, _progressIndicator);

}

在需要显示提示文字的地方调用ShowProgress(String message)方法。隐藏的地方调用HideProgress方法即可。

由于SystemTray.SetProgressIndicator(this, _progressIndicator);中this必须是  页面 的实例对象,为此在usercontrol控件想掉用此方法就必须找到usercontrol所在的页面。

写一个TreeExtensions的静态类用于获取页面

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

public static classTreeExtensions

{public static IEnumerable Ancestors(thisDependencyObject item)

{return item.Ancestors().Where(i => i is T).Cast();

}///

///返回可视树中所有父代元素集合(不包括本身)///

public static IEnumerable Ancestors(thisDependencyObject item)

{var parent =item.ParentEx();while (parent != null)

{yield returnparent;

parent=parent.ParentEx();

}

}///

public static DependencyObject ParentEx(thisDependencyObject item)

{returnVisualTreeHelper.GetParent(item);

}

}

View Code

获取页面代码:

var phonePage = this.Ancestors().FirstOrDefault();

同时using TreeExtensions类所在的命名空间。

把this 替换成phonePage即可。

可在任何地方调用的showtip代码段

当前页面通过PhoneApplicationPage page = (Application.Current.RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage;获取

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

public void showtip(stringtip)

{

PhoneApplicationPage page= (Application.Current.RootVisual as PhoneApplicationFrame).Content asPhoneApplicationPage;if (_progressIndicator == null)

{

_progressIndicator= newProgressIndicator();

}

_progressIndicator.Text=tip;

_progressIndicator.IsVisible= true;

_progressIndicator.IsIndeterminate= true;

SystemTray.SetProgressIndicator(page, _progressIndicator);

}privateProgressIndicator _progressIndicator;public voidHideProgress()

{if (_progressIndicator != null)

{

PhoneApplicationPage page= (Application.Current.RootVisual as PhoneApplicationFrame).Content asPhoneApplicationPage;

_progressIndicator.IsVisible= false;

SystemTray.SetProgressIndicator(page, _progressIndicator);

}

}

View Code

示例:http://files.cnblogs.com/fatlin/TestShowTip.rar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值