SettingsPane 類別

定義

注意

SettingsPane 已被取代,而且可能無法在所有版本的 Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針

靜態類別,可讓應用程式控制 [設定] [常用] 窗格。 應用程式可以新增或移除命令、在使用者開啟窗格時收到通知,或以程式設計方式開啟窗格。

public ref class SettingsPane sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.UI.ApplicationSettings.ApplicationsSettingsContract, 65536)]
/// [Windows.Foundation.Metadata.Deprecated("SettingsPane is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.UI.ApplicationSettings.ApplicationsSettingsContract)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
class SettingsPane final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.UI.ApplicationSettings.ApplicationsSettingsContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
/// [Windows.Foundation.Metadata.Deprecated("SettingsPane is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.UI.ApplicationSettings.ApplicationsSettingsContract")]
class SettingsPane final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.UI.ApplicationSettings.ApplicationsSettingsContract), 65536)]
[Windows.Foundation.Metadata.Deprecated("SettingsPane is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.UI.ApplicationSettings.ApplicationsSettingsContract))]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
public sealed class SettingsPane
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.UI.ApplicationSettings.ApplicationsSettingsContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
[Windows.Foundation.Metadata.Deprecated("SettingsPane is deprecated and might not work on all platforms. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.UI.ApplicationSettings.ApplicationsSettingsContract")]
public sealed class SettingsPane
Public NotInheritable Class SettingsPane
繼承
Object Platform::Object IInspectable SettingsPane
屬性

Windows 需求

裝置系列
Windows Desktop Extension SDK (已於 10.0.10240.0 引進)
Xbox One Extensions for the UWP (已於 10.0.10586.0 引進)
API contract
Windows.UI.ApplicationSettings.ApplicationsSettingsContract (已於 v1.0 引進)

範例

下列程式碼示範如何使用 SettingsPane 和 SettingsCommand 類別來新增應用程式命令。 如需完整範例,請參閱 應用程式設定範例

using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;

// This is the click handler for the 'addSettingsScenarioAdd' button.  
// Replace this with your own handler if you have a button or buttons on this page.
void addSettingsScenarioAdd_Click(object sender, RoutedEventArgs e)
{
    Button b = sender as Button;
    if (b != null)
    {
        rootPage.NotifyUser(
            "You selected the " + b.Content + " button", 
            NotifyType.StatusMessage);

        if (!this.isEventRegistered)
        {
            SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
            this.isEventRegistered = true;
        }
    }
}

void onSettingsCommand(IUICommand command)
{
    SettingsCommand settingsCommand = (SettingsCommand)command;
    rootPage.NotifyUser(
        "You selected the " + settingsCommand.Label + " settings command from the " + 
        SettingsPane.Edge.ToString(), NotifyType.StatusMessage);

}

void onCommandsRequested(
    SettingsPane settingsPane, 
    SettingsPaneCommandsRequestedEventArgs eventArgs)
{
    UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);

    SettingsCommand generalCommand = new SettingsCommand(
        "generalSettings", "General", handler);
    eventArgs.Request.ApplicationCommands.Add(generalCommand);

    SettingsCommand helpCommand = new SettingsCommand("helpPage", "Help", handler);
    eventArgs.Request.ApplicationCommands.Add(helpCommand);
}
Imports Windows.UI.ApplicationSettings
Imports Windows.UI.Popups
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System

    '' This is the click handler for the 'addSettingsScenarioAdd' button.  
    '' Replace this with your own handler if you have a button or buttons on this page.
    Private Sub addSettingsScenarioAdd_Click(sender As Object, e As RoutedEventArgs)
        Dim b As Button = TryCast(sender, Button)
        If b IsNot Nothing Then
            rootPage.NotifyUser("You selected the " & b.Content & " button", _
                NotifyType.StatusMessage)
            If Not Me.isEventRegistered Then
                AddHandler SettingsPane.GetForCurrentView.CommandsRequested, _
                    AddressOf onCommandsRequested
                Me.isEventRegistered = True
            End If
        End If
    End Sub

    Private Sub onSettingsCommand(command As IUICommand)
        Dim settingsCommand As SettingsCommand = DirectCast(command, SettingsCommand)
        rootPage.NotifyUser( _
        "You selected the " & settingsCommand.Label & " command from the " & SettingsPane.Edge.ToString(), _
        NotifyType.StatusMessage)
    End Sub

    Private Sub onCommandsRequested(settingsPane As SettingsPane, _
        eventArgs As SettingsPaneCommandsRequestedEventArgs)
        Dim handler As New UICommandInvokedHandler(AddressOf onSettingsCommand)

        Dim generalCommand As New SettingsCommand("generalSettings", "General", handler)
        eventArgs.Request.ApplicationCommands.Add(generalCommand)

        Dim helpCommand As New SettingsCommand("helpPage", "Help", handler)
        eventArgs.Request.ApplicationCommands.Add(helpCommand)
    End Sub


    '' This is the click handler for the 'addSettingsScenarioShow' button.  
    '' Replace this with your own handler if you have a button or buttons on this page.
    Private Sub addSettingsScenarioShow_Click(sender As Object, e As RoutedEventArgs)
        Dim b As Button = TryCast(sender, Button)
        If b IsNot Nothing Then
            rootPage.NotifyUser("You selected the " & b.Content & " button", _
                NotifyType.StatusMessage)
            SettingsPane.Show()
        End If
    End Sub
#include "pch.h"
#include "AddSettingsScenario.xaml.h"

using namespace ApplicationSettings;

using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::ApplicationSettings;
using namespace Windows::UI::Popups;

void ApplicationSettings::AddSettingsScenario::addSettingsScenarioAdd_Click(
    Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    Button^ b = safe_cast<Button^>(sender);
    if (b != nullptr)
    {
        rootPage->NotifyUser("You selected the " + b->Content + " button", 
            NotifyType::StatusMessage);
        if (!this->isEventRegistered)
        {
            this->commandsRequestedEventRegistrationToken = 
                SettingsPane::GetForCurrentView()->CommandsRequested += 
                    ref new TypedEventHandler<SettingsPane^, 
                    SettingsPaneCommandsRequestedEventArgs^>(this, 
                        &AddSettingsScenario::onCommandsRequested);
            this->isEventRegistered = true;
        }
    }
}

void ApplicationSettings::AddSettingsScenario::onSettingsCommand(
    Windows::UI::Popups::IUICommand^ command)
{
    SettingsCommand^ settingsCommand = safe_cast<SettingsCommand^>(command);
    rootPage->NotifyUser(
        "You selected the " + settingsCommand->Label + " settings command from the " + 
        SettingsPane::Edge.ToString(), NotifyType::StatusMessage);
}

void ApplicationSettings::AddSettingsScenario::onCommandsRequested(
    Windows::UI::ApplicationSettings::SettingsPane^ settingsPane,
    Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs^ eventArgs)
{
    UICommandInvokedHandler^ handler = ref new UICommandInvokedHandler(
        this, &AddSettingsScenario::onSettingsCommand);

    SettingsCommand^ generalCommand = ref new SettingsCommand(
        "generalSettings", "General", handler);
    eventArgs->Request->ApplicationCommands->Append(generalCommand);

    SettingsCommand^ helpCommand = ref new SettingsCommand("helpPage", "Help", handler);
    eventArgs->Request->ApplicationCommands->Append(helpCommand);
}

備註

注意

這個類別不是敏捷式的,這表示您需要考慮其執行緒模型和封送處理行為。 如需詳細資訊,請參閱執行緒和封送處理 (C++/CX) 在多執行緒環境中使用 Windows 執行階段 物件 (.NET)

屬性

Edge

注意

SettingsPane已被取代,而且可能無法在所有版本的 Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針

取得值,指出 [設定] 常用鍵是否出現在畫面的左邊緣或右邊緣。

方法

GetForCurrentView()

注意

SettingsPane已被取代,而且可能無法在所有版本的 Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針

取得與目前應用程式檢視相關聯的 SettingsPane 物件, (也就是 CoreWindow) 。

Show()

注意

SettingsPane已被取代,而且可能無法在所有版本的 Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針

向使用者顯示 [設定] [常用鍵] 窗格。

事件

CommandsRequested

注意

SettingsPane已被取代,而且可能無法在所有版本的 Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針

發生于使用者開啟設定窗格時。 接聽此事件可讓應用程式初始化設定命令,並暫停其 UI,直到使用者關閉窗格為止。

在此事件期間,請將 SettingsCommand 物件附加至可用的 ApplicationCommands 向量,使其可供 SettingsPaneUI 使用。

適用於

另請參閱