2017-01-23 75 views
0

当我的Windows Phone应用程序加载时我有一个定时器类,每隔一段时间衬托事件的背景。转换事件对象的DependencyObject的Windows Phone应用程序C#

我希望发生事件时运行ProgressIndicator在顶部显示的是。然而SystemTray.SetProgressIndicator需要一个依赖对象,我没有,因为我在一个静态内。有什么办法可以将对象发件人转换为依赖对象吗?有没有一种方法可以生成一个依赖对象?

下面是代码:

static public partial class TimerSync 
    { 
     static public void SetupTimer() 
     { 
      Timer.Interval = 15 
      Timer.Tick += Timer_Tick; 
      Timer.Start();   
     } 

     static public void Timer_Tick(object sender, EventArgs e) 
     { 
      var command = sender as DependencyObject; 
      SystemTray.SetProgressIndicator(command, MyApp.Global.ProgressShow("Syncing, please wait...")); 
      DoMyStuff(); 
      SystemTray.SetProgressIndicator(command, MyApp.Global.ProgressHide()); 
     } 
    } 

回答

0

我想你可以获取当前页面,并把它作为依赖的对象。

要小心这个,你应该首先检查值。

+0

感谢回去我。我已经试图与'变种当前页=((APP)Application.Current).RootFrame.Content作为的PhoneApplicationPage;',基本上这是行不通的。我并不十分确定背后的逻辑是什么,但我相信它是因为它独立于页面上发生的事情,并且不会被页面本身的回传调用。 –

相关问题