設定合約提供系統級設定面板整合,使用者可透過 Charms 列「設定」存取應用設定。支援應用自訂設定項目、系統代管設定(權限、評分)與裝置設定(音量、亮度)。


SettingsPane.GetForCurrentView().CommandsRequested 事件SettingsCommand 指定 ID、標籤、處理器ApplicationCommands 集合生效public App() {
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
}

private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) {
// 使用 Lambda 表達式
args.Request.ApplicationCommands.Add(new SettingsCommand(
"privacyPolicy", "隱私權政策", (handler) => {
LaunchUriAsync(new Uri("https://example.com/privacy"));
}));
// 使用 UICommandInvokedHandler
args.Request.ApplicationCommands.Add(new SettingsCommand(
"about", "關於", new UICommandInvokedHandler(OnAboutCommand)));
}

private void OnAboutCommand(IUICommand command) {
var flyout = new SettingsFlyout {
Title = "關於",
HeaderBrush = new SolidColorBrush(Colors.DarkBlue),
Content = new AboutUserControl(), // 自訂使用者控制項
Width = 346
};
flyout.Show();
}

在回呼中直接 args.Request.ApplicationCommands.Add(command) 即可。


設定合約讓應用設定整合至系統體驗。下一章將介紹應用程式列的概觀與設計規範。