请在代码中解释如何处理8.1 app的解锁屏幕事件。我实际上想从文本文件中读取下一行,并在每次我的屏幕解锁时将其显示在我的通知区域。请详细解释,因为我是c#的新手。
在MainPage.xaml.cs中编写此代码的位置?!
PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
rootFrame.Obscured += OnObscured;
rootFrame.Unobscured += Unobscured;
void OnObscured(Object sender, ObscuredEventArgs e)
{
}
void Unobscured(Object sender, EventArgs e)
{
}
答案 0 :(得分:0)
从我所看到的,我可以得出结论,这段代码:
PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
rootFrame.Obscured += OnObscured;
rootFrame.Unobscured += Unobscured;
应该放在你App
类的构造函数中(在App.cs
文件中),所以最终看起来像:
public class App
{
// more code could be here
public App()
{
PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
rootFrame.Obscured += OnObscured;
rootFrame.Unobscured += Unobscured;
}
// and some code could be here
void OnObscured(Object sender, ObscuredEventArgs e)
{
}
void Unobscured(Object sender, EventArgs e)
{
}
// and even here
}
p.s./offtop/一般建议:如果您是c#的新手,那么首先学习c#会更有意义,然后再深入了解winphone / asp / desktop / etc开发。这就是我个人的经历告诉我的。
希望这会有所帮助