SettingsCommand 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
注意
SettingsPane已被取代,而且可能無法在所有版本的Windows 10上運作。 不要使用 SettingsPane,而是將設定選項整合到應用程式體驗中。 如需詳細資訊,請參閱 應用程式設定的指導方針。
建立代表設定專案的 settings 命令物件。 這個設定命令可以附加至 ApplicationCommands 向量。
public ref class SettingsCommand sealed : IUICommand
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.ApplicationSettings.ISettingsCommandFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
class SettingsCommand final : IUICommand
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.ApplicationSettings.ISettingsCommandFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class SettingsCommand final : IUICommand
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.ApplicationSettings.ISettingsCommandFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
public sealed class SettingsCommand : IUICommand
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.None)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.ApplicationSettings.ISettingsCommandFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class SettingsCommand : IUICommand
function SettingsCommand(settingsCommandId, label, handler)
Public NotInheritable Class SettingsCommand
Implements IUICommand
- 繼承
- 屬性
- 實作
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 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",
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);
}
#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 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 AddSettingsScenario::OnSettingsCommand(
Windows::UI::Popups::IUICommand^ command)
{
SettingsCommand^ settingsCommand = safe_cast<SettingsCommand^>(command);
rootPage->NotifyUser(
"You selected the " + settingsCommand->Label + " settings command",
NotifyType::StatusMessage);
}
void 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);
}
#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",
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);
}
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 & " settings command", _
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
備註
注意
這個類別不是敏捷的,這表示您必須考慮其執行緒模型和封送處理行為。 如需詳細資訊,請參閱執行緒和封送處理 (C++/CX) 和在多執行緒環境中使用 Windows 執行階段 物件 (.NET) 。
建構函式
SettingsCommand(Object, String, UICommandInvokedHandler) |
建立新的設定命令。 |
屬性
AccountsCommand |
取得帳戶設定窗格中 Web 帳戶的命令。 |
Id |
取得或設定命令識別碼。 |
Invoked |
取得或設定使用者選取命令時所引發之事件的處理常式。 |
Label |
取得或設定命令的標籤。 |