Search code examples
xamlwindows-8settingscharms-bar

How can i set settings propperties in charms bar in XAML, Windows 8?


I'm trying to get the charms bar working in windows 8, but i can't find any thing using google.

What i want is to let users acces settings and privacy policy throuw charms bar.

I all ready have this:

    public MainPage()
    {
        this.InitializeComponent();
        SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
    }

    void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
    {
        args.Request.ApplicationCommands.Add(new SettingsCommand("commandid", "Settings", DoOperation));
    }

    private async void DoOperation(IUICommand command)
    {
        //Show the Settings or Privacy Policy HERE!
    }

I don't know how i can get my settings in place of: //Show the Settings or Privacy Policy HERE!

Any help or rather code samples would be greate.


Solution

  • It's better if you put the code in App.xaml.cs, here's a working example:

    protected async override void OnLaunched(LaunchActivatedEventArgs args)
    { /....
       SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
       //before if (!rootFrame.Navigate(typeof...
    }
    void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
              var privacy =  new SettingsCommand("privacyPref", "Privacy Plicy",
                (uiCommand) => { Windows.System.Launcher.LaunchUriAsync(new Uri("http://YOURURL.COM")); });
            args.Request.ApplicationCommands.Add(privacy);
            var preferences = new SettingsCommand("preferences", "Preferences", (handler) =>
            {
                var settings = new SettingsFlyout(); //Callisto extension
                settings.Content = new PreferencesUserControl(); //Add New Element->User Control
                settings.HeaderBrush = new SolidColorBrush(_background);
                settings.Background = new SolidColorBrush(_background);
                settings.HeaderText = "Preferences";
                settings.IsOpen = true;
            });
        }