Windows 8 系列 -- ApplicationSettings --随笔

本文详细介绍了如何在设置面板中添加命令,并通过弹出窗口实现个性化用户交互,包括命令的触发、执行以及弹出窗口的显示与关闭逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//向设置面板加入事件
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
 // 点击时触发,添加一项
        void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            //定义执行处理事件
            UICommandInvokedHandler handle = new UICommandInvokedHandler(onSettingsCommand);
            //定义设置命令项
            SettingsCommand generalCommand = new SettingsCommand("generalSettings", "general", handle);
            //将命令项添加到设置集合
            args.Request.ApplicationCommands.Add(generalCommand);
         }
 //执行命令项事件
        void onSettingsCommand(IUICommand command)
        {
            SettingsCommand settingsCommand = (SettingsCommand)command;
            showBlock.Text = settingsCommand.Label;
        }
//定义popup窗体 
private Popup settingsPopup;
 void onSettingsCommand1(IUICommand command)
        {
            settingsPopup = new Popup();
       //popup关闭时 settingsPopup.Closed
+= settingsPopup_Closed; Window.Current.Activated += Current_Activated; settingsPopup.IsLightDismissEnabled = true; settingsPopup.Width = settingsWidth; settingsPopup.Height = windowBounds.Height; settingsPopup.ChildTransitions = new TransitionCollection(); settingsPopup.ChildTransitions.Add(new PaneThemeTransition() { Edge = (SettingsPane.Edge == SettingsEdgeLocation.Right) ? EdgeTransitionLocation.Right : EdgeTransitionLocation.Left }); //将用户xmal 添加到Popup中 SettingsFlyout mypane = new SettingsFlyout(); mypane.Width = settingsWidth; mypane.Height = windowBounds.Height; settingsPopup.Child = mypane; settingsPopup.SetValue(Canvas.LeftProperty, SettingsPane.Edge == SettingsEdgeLocation.Right ? (windowBounds.Width - settingsWidth) : 0); settingsPopup.SetValue(Canvas.TopProperty, 0); settingsPopup.IsOpen = true; }
void settingsPopup_Closed(object sender, object e)
        {
            Window.Current.Activated -= Current_Activated;
        }
 void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
        {
            //throw new NotImplementedException();
            if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
            {
                settingsPopup.IsOpen = false;
            }
        }

转载于:https://www.cnblogs.com/Jusoc/archive/2012/11/06/2757764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值