title: How to save selected index of a combobox in UWP and display it back when the user reloads the page?
body: <p>I have a <code>ComboBox</code> control in my UWP application and I need to save the selected index of it when the user is selecting an option! Then, I need to save this index in local settings and when the user is coming back on this page, I want the <code>ComboBox</code> to have this saved index as the selected index. I need this functionality in my settings page! Can anyone help me? </p>
  
  <p>This is my code:</p>
  
  <pre><code>private void fuelTypeSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
      var localSettings = ApplicationData.Current.LocalSettings;
  
      try
      {
          if(localSettings.Values.ContainsKey("selectedIndex"))
          {
              int index = (int)localSettings.Values["selectedIndex"];
              fuelTypeSelector.SelectedIndex = index;
  
              //update the saved index
  
              if(fuelTypeSelector.SelectedIndex!=index)
              {
                  localSettings.Values["selectedIndex"] =
                      fuelTypeSelector.SelectedIndex;
              }
          }
          else
          {
              // index does not exist
              localSettings.Values.Add("selectedIndex",
                  fuelTypeSelector.SelectedIndex);
          }
      }
      catch(Exception ex)
      {
  
      }
  }
  </code></pre>