Windows 8 Store Apps學習(59) 鎖屏

來源:互聯網
上載者:User

介紹

重新想象 Windows 8 Store Apps 之 鎖屏

登入鎖屏,擷取當前程式的鎖屏許可權,從鎖屏中移除

發送徽章或文本到鎖屏

將一個 app 的多個 tile 綁定到鎖屏

自訂鎖屏圖片

樣本

1、示範如何登入鎖屏,擷取當前程式的鎖屏許可權,從鎖屏中移除

LockScreen/AccessLockScreen.xaml

<Page    x:Class="XamlDemo.LockScreen.AccessLockScreen"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:XamlDemo.LockScreen"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d">        <Grid Background="Transparent">        <StackPanel Margin="120 0 0 0">                            <TextBlock Name="lblMsg" FontSize="14.667" />                <Button Name="btnRequestAccess" Content="請求登入鎖屏" Margin="0 10 0 0" Click="btnRequestAccess_Click" />                <Button Name="btnGetAccessStatus" Content="擷取當前程式的鎖屏許可權" Margin="0 10 0 0" Click="btnGetAccessStatus_Click" />                <Button Name="btnRemoveAccess" Content="從鎖屏中移除" Margin="0 10 0 0" Click="btnRemoveAccess_Click" />            </StackPanel>    </Grid></Page>

LockScreen/AccessLockScreen.xaml.cs

/* * 示範如何登入鎖屏,擷取當前程式的鎖屏許可權,從鎖屏中移除 *  * 註: * 要想請求鎖屏許可權,需要背景工作支援“推播通知”或“控制通道” */    using System;using Windows.ApplicationModel.Background;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;    namespace XamlDemo.LockScreen{    public sealed partial class AccessLockScreen : Page    {        public AccessLockScreen()        {            this.InitializeComponent();        }            private async void btnRequestAccess_Click(object sender, RoutedEventArgs e)        {            try            {                // 向系統請求登入鎖屏,會彈出確認對話方塊                //     需要背景工作支援“推播通知”或“控制通道”,否則會拋出異常                //     不能在模擬器中運行                //     如果 BackgroundAccessStatus 不等於 Unspecified,則即使調用 RequestAccessAsync() 也不會出現對話方塊,需要使用者去“設定”中去添加或移除鎖定畫面 app                BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();                    /*                 * BackgroundAccessStatus - 當前 app 的鎖屏許可權                 *     Unspecified - 使用者尚未選擇                 *     Denied - 被使用者拒絕                 *     AllowedWithAlwaysOnRealTimeConnectivity - 用於允許了,且支援即時串連,即使電量低                 *     AllowedMayUseActiveRealTimeConnectivity - 用於允許了,且支援即時串連,但是如果電量低則無法即時串連                 */                    lblMsg.Text = "RequestAccessAsync(): " + status.ToString();            }            catch (Exception ex)            {                lblMsg.Text = ex.ToString();            }        }            private void btnGetAccessStatus_Click(object sender, RoutedEventArgs e)        {            try            {                // 擷取當前應用程式的鎖屏許可權                BackgroundAccessStatus status = BackgroundExecutionManager.GetAccessStatus();                lblMsg.Text = "GetAccessStatus(): " + status.ToString();            }            catch (Exception ex)            {                lblMsg.Text = ex.ToString();            }        }            private void btnRemoveAccess_Click(object sender, RoutedEventArgs e)        {            try            {                // 將當前應用程式從鎖屏中移除                BackgroundExecutionManager.RemoveAccess();                lblMsg.Text = "RemoveAccess()";            }            catch (Exception ex)            {                lblMsg.Text = ex.ToString();            }        }    }}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.