locked
Hiding Settings/SettingsPane when user is logged out? RRS feed

  • Question

  • Hi,

    I am working on a Windows 8.1 app which can be protected with a passcode. If a passcode is set the main page simply shows a PopUp on launch to prompt for the code. This works fine, the user cannot enter/use the app without the code. However app settings are always available in the settings charm, no matter if the user is logged in or not.

    I followed the documentation to add the customs settings to the settings charm:

    protected override void OnWindowCreated(WindowCreatedEventArgs args) { SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; } private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { args.Request.ApplicationCommands.Add(new SettingsCommand(..., ..., (handler) => ShowCustomSettingFlyout())); } public void ShowCustomSettingFlyout() {
    if (IsLoggedIn()) { CustomSettingsFlayout flyout = new CustomSettingsFlayout (); flyout .Show();

    } }

    The only way I found to prevent the user from accessing the settings when he is not loggin in, is the if-statement in ShowCustomSettingsFlyout(). However this is not really a good solution. This means that the settings are visible in the settings pane but do not react to user input. It would be way better if the settings would only be visible when the user is logged in.

    The passcode is not only necessary when the app is launched but also when the user left the app for a certain time and returns to it later. That means that I would have to be able to disable and enable the settings at runtime. Is this possible?



    Thursday, January 23, 2014 2:02 PM

Answers

  • Did you try registering the pane after logon:

    SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;

    And deregistering it again when the user logs off (just before the Popup opens):

    SettingsPane.GetForCurrentView().CommandsRequested -= OnCommandsRequested;

    • Marked as answer by Agenor Thursday, January 23, 2014 2:24 PM
    Thursday, January 23, 2014 2:13 PM

All replies

  • Did you try registering the pane after logon:

    SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;

    And deregistering it again when the user logs off (just before the Popup opens):

    SettingsPane.GetForCurrentView().CommandsRequested -= OnCommandsRequested;

    • Marked as answer by Agenor Thursday, January 23, 2014 2:24 PM
    Thursday, January 23, 2014 2:13 PM

  • Thank you very much! I totally missed that OnCommandRequested is called everytime the settings pane is shown. I thought it would only be called once on start up.
    Thursday, January 23, 2014 2:24 PM