Settings Pane in Charm

using Windows.UI.ApplicationSettings;

        Rect _windowBounds;
        double _settingsWidth = 364;
        Popup _settingsPopup;
        public MainPage()
        {
            this.InitializeComponent();          
            Windows.UI.ApplicationSettings.SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
            Window.Current.SizeChanged += Current_SizeChanged;
            _windowBounds = Window.Current.Bounds;
        }

        void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
        {
            _windowBounds = Window.Current.Bounds;
        }

        void MainPage_CommandsRequested(Windows.UI.ApplicationSettings.SettingsPane sender, Windows.UI.ApplicationSettings.SettingsPaneCommandsRequestedEventArgs args)
        {
            SettingsCommand cmd=new SettingsCommand ("","Help",async (x)=>{
                Uri helpURL = new Uri("http://www.google.com");
                await Windows.System.Launcher.LaunchUriAsync(helpURL);
            });            
            args.Request.ApplicationCommands.Add(cmd);

            cmd = new SettingsCommand("", "Settings", (x) =>
            {
                _settingsPopup = new Popup();
                _settingsPopup.Closed += _settingsPopup_Closed;
                Window.Current.Activated += OnWindowActivated;
                _settingsPopup.IsLightDismissEnabled = true;
                _settingsPopup.Width = _settingsWidth;
                _settingsPopup.Height = _windowBounds.Height;

                SettingsPage sp = new SettingsPage();
                sp.Width = _settingsWidth;
                sp.Height = _windowBounds.Height;

                _settingsPopup.Child = sp;
                _settingsPopup.SetValue(Canvas.LeftProperty, _windowBounds.Width - _settingsWidth);
                _settingsPopup.SetValue(Canvas.TopProperty, 0);
                _settingsPopup.IsOpen = true;
            });
            args.Request.ApplicationCommands.Add(cmd);
        }

      
        void _settingsPopup_Closed(object sender, object e)
        {
            Window.Current.Activated -= OnWindowActivated;
        }
        void OnWindowActivated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
        {
            if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
            {
                _settingsPopup.IsOpen = false;
            }
        }

 

在SettingsPage中:

using Windows.UI.ApplicationSettings;

           private void btgoBack_Click_1(object sender, RoutedEventArgs e)
        {
            if (this.Parent.GetType() == typeof(Popup))
            {
                ((Popup)this.Parent).IsOpen = false;
                SettingsPane.Show();
            }

        } 

 

转载于:https://www.cnblogs.com/qixue/archive/2013/01/16/2863090.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值