当前位置:编程学习 > wap >>

Windows Phone 7–SystemTray与ProgressIndicator(wp的progressDialog)

这一篇内容主要介绍一个大家撰写App时第一件会做的事,「隐藏画面最上方的系统轴」;
  在Android或iOS裡,只有在游戏模戏下,才能隐藏系统轴,其余最多只能隐藏显示应用程式的标题列。
  但我在猜想:「是否由于iOS/Android可由顶端往下拉出通知範围,所以不能隐藏系统轴?」,也许未来WP也支援类似的功能后,系统轴隐藏的功能也不能了,但这只是猜测,先让我们来看看怎么实作吧。
  〉SystemTray:
  属于Microsoft.Phone.Shell Namespace裡的类别,主要任务为提供Application Page上System Tray的方法与属性。
  几个要注意的属性与方法:

 
方法/属性 说明
CheckAccess 用于确定唿叫该属性的Thread是否有存取该物件的能力。 
CheckAccess是个Utility方法, 
true:代表唿叫的Thread与要操作的DependencyObject属于相同的Thread; 
false:代表建立该DependencyObject的Thread与唿叫的Thread不相同; 
如果是false则会出现Exception要特别注意。
GetProgressIndicator 取得Application Page中的ProgressIndicator的物件/属性。
SetProgressIndicator 设定Application Page中的ProgressIndicator的物件/属性。
 


往下继续说明怎么操作SystemTray。
  a. 开启/关闭System Tray:
   1: //記得using Microsoft.Phone.Shell namespace
   2: 
   3: private void ChangeSystemTray(bool pVisible)
   4: {
   5:     // true: 顯示; false: 隱藏;
   6:     SystemTray.IsVisible = pVisible;
   7: }
  b. 在System Tray裡得到那些Status Icons呢?根据的介绍,包括如下图:
  

 



〉ProgressIndicator:
  该类别用意在提供每个Application Page上的System Tray有一个互动的progress indicator。WP 7.1 SDK新增加的,以前在WP 7.0 SDK裡没有这个类别,所以如果程式裡需要做到背景执行的任务时,通常会popup一个Progressbar,
  让使用者知道目前正在处理交易,请他们等待。那么,要如何使用它呢?
  a. 使用Code建立ProgressIndicator:
   1: private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
   2: {
   3:     //需要確實把SystemTray.IsVisible = true,ProgressIndicator才能顯示
   4:     Microsoft.Phone.Shell.SystemTray.IsVisible = true;
   5:           
   6:     //建立一個新的ProgressIndicator
   7:     ProgressIndicator tProgIndicator = new ProgressIndicator();
   8:     tProgIndicator.IsVisible = true;
   9:     //操作與ProgressBar相同的屬性 www.zzzyk.com
  10:     tProgIndicator.IsIndeterminate = true;
  11:     tProgIndicator.Text = "Loading...";
  12:     //將ProgressIndicator加入SystemTray之中,並指定DependencyObject為Application Page。
  13:     SystemTray.SetProgressIndicator(this, tProgIndicator);
  14: }
  b. 使用XAML建立ProgressIndicator:
   1: <shell:SystemTray.ProgressIndicator>
   2:     <shell:ProgressIndicator IsIndeterminate="True"
   3:             IsVisible="True" Text="Loading..." />
   4: </shell:SystemTray.ProgressIndicator>
  了解ProgressIndicator的建立方式之后,在使用时机上有一个要特别注意的:
  1. 使用Popup来显示ProgressBar可以在Application Page上在盖上一个UI Control,告知使用者目前不可操作画面;
  2. 使用ProgressIndicator,其Application Page上的画面是可以继续操作的,因此需注意使用的情境与对象;
  [补充]
  ‧ 如何动态取得目前画面的Width/Height;
  如果想使用目前画面的Size来修改要呈现的UI Control时,直接使用Application Page的Width/Height是不行的,建议可以使用:「App.Current.RootVisual.RenderSize.Height」或「App.Current.RootVisual.RenderSize.Width」;
  使用时机在Application Page的Loaded事件之后。
  ======
  概略地说明与补充了相关SystemTray的应用与经验,希望对大家在开发上有所帮助。感谢。

 

 

摘自 xiechengfa的专栏

补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,