Why we need custom settings page in our applications?

Adding a settings page to your application is a nice way to tell users that you really care about them.

All the user preferences and customization for any specific app should be maintained through settings where your user can easily update and save them accordingly instead of setting few options every time.

So just follow the steps listed below to add a settings page to your application (s):

Note: I assume that you have already created a blank windows universal application project.

Steps

    1. Add few TextBlocks in your MainPage.xaml to view the saved settings as below:
      
      

 

  • Create a Page Load event in your MainPage.xaml.cs’ constructor as:
    public MainPage()
            {
                this.InitializeComponent();
                this.Loaded += MainPage_Loaded;
            }
    
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
    
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                //If condition is checking if the settings keys exists or not
                if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("name") || Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("phone"))
                {
                   nameLbl.Text=localSettings.Values["name"].ToString();
                   phoneLbl.Text=localSettings.Values["phone"].ToString();
    
                }
                else
                {
                    nameLbl.Text = "Currently there are no settings available.";
                }
            }
    

    Now add a navigation functionality to your update settings button for navigating to settings page as:

     this.Frame.Navigate(typeof(Settings));
    
  • Now add a new page , name it as settings.xaml and add few textboxes according to your need as:
    
    

     

 

 

  • Now inside the click event of your button on settings page add the following code:
     var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                 localSettings.Values["name"] = nameBox.Text;
                    localSettings.Values["phone"] = phoneBox.Text;
    
                    this.Frame.Navigate(typeof(MainPage));
    

 

Download Sample Project

That’s All.
Happy Coding