0

On the App.xaml.cs I have the following code

private async void OnCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs e)
    {
        var loader = ResourceLoader.GetForCurrentView();

        var generalCommand = new SettingsCommand("General Settings", "General Settings", handler =>
        {
            var generalSettings = new GeneralSettingsFlyout();
            generalSettings.Show();
        });
        e.Request.ApplicationCommands.Add(generalCommand);

        object data;
        IAuthService _authService = new AuthService();
        if (Global.UserId == 0)
            data = await _authService.GetSettingValueBySettingName(DatabaseType.GeneralDb, ApplicationConstants.GeneralDbSettingNames.ShowSupportInfo);
        else
            data = await _authService.GetSettingValueBySettingName(DatabaseType.UserDb, ApplicationConstants.UserDbSettingNames.ShowSupportInfo);

        if (data != null && data.ToString().Equals("1"))
        {
            var supportCommand = new SettingsCommand("Support", "Support", handler =>
            {
                var supportPane = new SupportFlyout();
                supportPane.Show();
            });
            e.Request.ApplicationCommands.Add(supportCommand);
        }

        var aboutCommand = new SettingsCommand("About", loader.GetString("Settings_OptionLabels_About"), handler =>
       {
           var aboutPane = new About();
           aboutPane.Show();
       });
       e.Request.ApplicationCommands.Add(aboutCommand);           

}

This code adds the setting "General Settings" but neither "Support" or "About" commands. Can anyone advice what's wrong with this code?

1
  • PS: All code executes successfully and no exceptions are throwing either. Commented Nov 11, 2016 at 8:48

1 Answer 1

1

Instead of querying the commands from your service when they are requested you'll need to query them ahead of time and then add the already known commands.

You cannot use await in OnCommandsRequested.

A method returns when it gets to the first await, so only commands added to the request before the await will be used.

Since the SettingsPaneCommandsRequestedEventArgs doesn't provide a deferral there is no way to tell the requester to wait for internal async calls to complete.

Note also that SettingsPane is deprecated and not recommended for new app development for Windows 10.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.