locked
How to remove the settings charms button after adding ? RRS feed

  • Question

  • I have a login page this start page show the default settings than after I login the settings will show the signout. After I signout I am back to the login page. But I cannot hide or remove the signout in the settings.

    Here is the code:

    void onSettingsCommand(IUICommand command)
            {
                SettingsCommand settingsCommand = (SettingsCommand)command;
                //rootPage.NotifyUser("You selected the " + settingsCommand.Label + " settings command which originated from the " + SettingsPane.Edge.ToString(), NotifyType.StatusMessage);
    
                if (settingsCommand.Id.Equals("signOut"))
                {
                    if (!this.isEventRegistered)
                    {
                        // Listening for this event lets the app initialize the settings commands and pause its UI until the user closes the pane.
                        // To ensure your settings are available at all times in your app, place your CommandsRequested handler in the overridden
                        // OnWindowCreated of App.xaml.cs
                        SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
                        this.isEventRegistered = true;
                    }
                    this.Frame.Navigate(typeof(MainPage));
                }
            }
    
            void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
            {
                UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);
    
                SettingsCommand helpCommand = new SettingsCommand("helpPage", "Help", handler);
                eventArgs.Request.ApplicationCommands.Add(helpCommand);
    
                SettingsCommand generalCommand = new SettingsCommand("signOut", "Signout", handler);
                eventArgs.Request.ApplicationCommands.Add(generalCommand);
    
                //eventArgs.Request.ApplicationCommands.Remove(helpCommand);
            }

    This above code is from the msdn than I modified.

    Than I create another method but it don't seems to work

    void onCommandsRequest(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
            {
                UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);
                this.onCommandsRequested(settingsPane, eventArgs);
    
                SettingsCommand helpCommand = new SettingsCommand("helpPage", "Help", handler);
                eventArgs.Request.ApplicationCommands.Remove(helpCommand);
    
                SettingsCommand generalCommand = new SettingsCommand("signOut", "Signout", handler);
                eventArgs.Request.ApplicationCommands.Remove(generalCommand);
            }


    Thanks, Smiths

    Wednesday, August 14, 2013 1:51 AM

All replies

  • Only the commands you add in the current call to onCommandsRequested will be shown.

    You don't need to remove the commands from a previous call to onCommandsRequested: just don't add the ones you don't want to see now.

    --Rob

    Wednesday, August 14, 2013 2:19 AM
    Moderator
  • Which means ? The above codes all reside in the LoginPage only.

    Thanks.


    Thanks, Smiths

    Wednesday, August 14, 2013 2:42 AM
  • You don't need to remove anything from the settings pane.

    Every time the settings pane opens it starts fresh with no items before requesting that the app add any relevant commands. The app can choose to add some commands and not add others depending on the state of the app.

    --Rob

    Wednesday, August 14, 2013 10:30 PM
    Moderator
  • I don't understand the example from msdn the part on AddSettingsScenario code behind

            protected override void OnNavigatedFrom(NavigationEventArgs e)
            {
                base.OnNavigatedFrom(e);
    
                // Added to make sure the event handler for CommandsRequested in cleaned up before other scenarios
                if (this.isEventRegistered)
                {
                    SettingsPane.GetForCurrentView().CommandsRequested -= onCommandsRequested;
                    this.isEventRegistered = false;
                }
            }

    I don't really understand this part code. Thanks.


    Thanks, Smiths

    Thursday, August 15, 2013 1:49 AM
  • That removes the event handler when you leave the page so that the page can be garbage collected. This prevents a memory leak. This is standard practice for all event handlers and is not specific to the settings pane.

    --Rob

    Thursday, August 15, 2013 1:56 AM
    Moderator
  • Ok thanks for the reply. Can I know if I can set the settings in the app.xaml.cs which mean I will call it when I need it in other pages ? Thanks.

    Thanks, Smiths

    Thursday, August 15, 2013 1:58 AM