Why is this Element not Found?

前端 未结 1 816
无人共我
无人共我 2021-01-28 00:17

I added code to my Windows Store App project to utilize the Settings pane for my app\'s custom settings. I based this code on what is in Adam Nathan\'s book \"Windows 8 Apps wit

1条回答
  •  伪装坚强ぢ
    2021-01-28 01:09

    In your case SettingsPane.GetForCurrentView() is throwing an exception because you're calling it too early. You are configuring the settings for a specific view, but in the application constructor there is no view yet, hence Element not found.

    Move you code to a page without changing anything and it will work:

    public MainPage()
    {
        this.InitializeComponent();
        SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
    }
    
    private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs spcreArgs)
    {
        spcreArgs.Request.ApplicationCommands.Add(new SettingsCommand(1, "App Bar Color", OnSettingsCommand));
        spcreArgs.Request.ApplicationCommands.Add(new SettingsCommand(2, "Visit Types to Display", OnSettingsCommand));
        spcreArgs.Request.ApplicationCommands.Add(new SettingsCommand(3, "Display Current Location", OnSettingsCommand));
        spcreArgs.Request.ApplicationCommands.Add(new SettingsCommand(4, "Set Home Base", OnSettingsCommand));
    }
    
    private void OnSettingsCommand(Windows.UI.Popups.IUICommand command)
    {
        int id = (int)command.Id;
        switch (id)
        {
            case 1:
                //Bla => I think this is where I need to add "this.[custom settings pane (user control) name].Show(command)
                break;
            case 2:
                //Bla
                break;
            case 3:
                //Bla
                break;
            case 4:
                //Bla
                break;
        }
    }
    

    0 讨论(0)
提交回复
热议问题