【问题标题】:Universal app detect start focus lost通用应用程序检测开始焦点丢失
【发布时间】:2014-11-14 21:15:06
【问题描述】:

我正在为 WP8.1 编写一个通用应用程序,我不希望它暂停。

一些银行应用程序是这样的。如果银行应用程序正在运行并且我单击后退按钮或开始按钮,则该应用程序不会暂停。它退出。我想开发人员不希望银行帐户凭据挂在状态数据中。

我正在尝试为我的安全消息传递应用程序做同样的事情。我可以在后退按钮上放置一个事件:

Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

在这个事件处理程序调用内部:

App.Current.Exit();

这行得通。

但我如何检测应用是否因用户按下开始按钮、搜索按钮或关闭按钮而失去焦点?

我已经在 App 类中尝试过这个事件:

Window.Current.Activated += Current_Activated;

还有这个函数,也在App类中:

protected override void OnActivated(IActivatedEventArgs args)

但它们都没有被调用。

【问题讨论】:

    标签: windows-phone-8.1 win-universal-app


    【解决方案1】:

    像这样:

    public sealed partial class App : Application
    {
        /* --- Omitted generated code here --- */
    
        protected override void OnWindowCreated(WindowCreatedEventArgs args)
        {
            args.Window.VisibilityChanged += Window_VisibilityChanged;
        }
    
        void Window_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
        {
            if (!e.Visible)
                Exit();
        }
    }
    

    【讨论】:

    • 就是这样!感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 2010-09-07
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多