0
votes

how to view specific setting page in winrt application using C# from outside button click?

In javascript i found like this WinJS.UI.SettingsFlyout.showSettings("About", "/Settings/About.html")

But i could not able to find this in c#,I am using callisto for Setting Flyouts

3

3 Answers

7
votes

I'm using Callisto and C# too, and this is how I solved the problem.

    void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
    {
        var settings = new SettingsCommand("settings", "Settings", new UICommandInvokedHandler(showSettings));
        args.Request.ApplicationCommands.Add(settings);
        var credits = new SettingsCommand("credits", "Credits", new UICommandInvokedHandler(showCredits));
        args.Request.ApplicationCommands.Add(credits);
    }

    public void showSettings(IUICommand command)
    {
        var settings = new SettingsFlyout();
        settings.Content = new SettingsUserControl();
        settings.HeaderBrush = new SolidColorBrush(_background);
        settings.Background = new SolidColorBrush(_background);
        settings.HeaderText = "Settings";
        settings.IsOpen = true;
    }

    public void showCredits(IUICommand command)
    {
        var settings = new SettingsFlyout();
        settings.Content = new CreditsUserControl();
        settings.HeaderBrush = new SolidColorBrush(_background);
        settings.Background = new SolidColorBrush(_background);
        settings.HeaderText = "Credits";
        settings.IsOpen = true;
    }

Then from other pages I can just call

((App)Application.Current).showCredits(null);  

or

((App)Application.Current).showSettings(null);

To bring up the settings pane I want to see :o)

1
votes

The first step is to add a listener for the CommandsRequest event on the SettingsPane for the page where you want the setting to be displayed. For example:

SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;

Then define the event handler

void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    SettingsCommand generalCommand = new SettingsCommand("GeneralSettings", ResourceLoader.GetString("GeneralText"), (x) =>
    {
        SettingsFlyout settings = new SettingsFlyout();
        settings.HeaderBrush = Resources["SettingsHeaderBrush"] as SolidColorBrush;
        settings.HeaderText = ResourceLoader.GetString("GeneralText");
        settings.Background = new SolidColorBrush(Windows.UI.Colors.White);
        settings.Content = new GeneralSettingsFlyout();
        settings.IsOpen = true;
        settings.Height = Window.Current.Bounds.Height;

        // Optionally, add a closed event handler
        settings.Closed += settings_Closed;
    });
}

Note that in this scenario, GeneralSettingsFlyout is simply a Page which will be loaded into the settings pane once that particular setting is selected (Callisto automatically handles this).

SettingsFlyout is the class from Callisto.

0
votes

Edit your app.xaml file and reference this snippet for your code:

App::OnLaunched()
{
.
.
     var rootFrame = new CharmFrame { CharmContent = new CharmFlyouts() };
     SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
.
.
}

Then, when you want to display that setting, do this:

SomeOtherMethod()
{
     ((Window.Current.Content as CharmFrame).CharmContent as CharmFlyouts).ShowSettings();
}