积极答复者
OnSuspending 的一些问题

问题
答案
-
如果是这样的话,你可以用 Window.Current.VisibilityChanged += Current_VisibilityChanged; 事件
然后在里面判断是否可见:
void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) { if (e.Visible == false) //TO DO }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 HelloWin8 2012年5月4日 6:44
全部回复
-
当程序挂起的时候,任务管理器中的挂起程序会有一个“Suspending”的提示。你按Alt+F4直接终止程序了啊。关于怎么实现的问题,基本微软官方的例子都有,你下来看看
- 已建议为答案 Leo06053308 2012年5月2日 8:23
- 取消建议作为答案 Leo06053308 2012年5月2日 8:23
-
如果是这样的话,你可以用 Window.Current.VisibilityChanged += Current_VisibilityChanged; 事件
然后在里面判断是否可见:
void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) { if (e.Visible == false) //TO DO }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 HelloWin8 2012年5月4日 6:44
-
Dear Bob:
我的代码是这样的:
public App() { this.InitializeComponent(); this.Suspending += OnSuspending; Window.Current.VisibilityChanged += Current_VisibilityChanged; } void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) { throw new NotImplementedException(); }
但是在运行的时候会出现问题:
WinRT information: Call to IFrameworkView::Initialize failed
The thread '<No Name>' (0x13d0) has exited with code 0 (0x0).
The program '[988] Application2.exe: Managed (v4.0.30319)' has exited with code 1 (0x1). -
throw new NotImplementedException();
这个是VS帮你生成的,你需要将其去掉,否则它也是一个异常啊。抛出没有被处理就会导致应用崩溃。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
It's OK now, very Thanks!
I put the code in the other places, not in the App class:
public ItemsPage() { this.InitializeComponent(); Window.Current.VisibilityChanged += Current_VisibilityChanged; } void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) { Debug.WriteLine("Current_VisibilityChanged......."); }