This post covers storing and retrieving settings with a WPF combobox for the UI. If you are looking for a solution to store settings across devices, for instance a Windows Surface tablet and a Windows Phone powered device, you should check out the blog of Mike Taulty. That is called roaming data storage. And if you are not working on an app for Windows RT/metro or Windows Phone but are just coding some WPF application, you should read this post from Scott Hanselman.

Let’s start with some code now that it’s clear what this post covers and what it doesn’t cover.

Here is my XAML from my userinterface:

<ComboBox x:Name="cbCountry" 
    PlaceholderText="Select country" SelectedValuePath="Tag">
    <ComboBoxItem Content="Australia" Tag="au"/>
    <ComboBoxItem Content="New Zealand" Tag="nz"/>

Please note the ‘SelectedValuePath’ is being set to ‘Tag’, otherwise it would grab the ‘comboboxitem’ or ‘content’ like this:

var comboboxContent = ((ComboBoxItem)cbCountry.SelectedValue).Content;

With the value path set to tag, it will grab ‘au’ or ‘nz’ as selected value.

This is the constructor of the xaml page containing my settings.

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;


if (localSettings.Values.ContainsKey("country"))
    cbCountry.SelectedValue = localSettings.Values["country"];

and this is the code for the selectionchanged event of the combobox.

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    localSettings.Values["country"] = cbCountry.SelectedValue;

Good luck with this small code sample. If this is not what you are looking for, please check the links mentioned at the start. I strongly believe that they take you to the code that you are looking for (if the code above is insufficient)

Pin on pinterest Plus on Googleplus Post on LinkedIn
Well, I was wondering the same, because LinkedIn lost a few million passwords. It’s out on the web in a zip. So if you have downloaded the file to check if your password is in it, you won’t be able to see your password because it is encoded. So that is the reason I wrote this tiny WPF Windows application, to have a textbox, button and output label. Basically this does take the password you type in, hash it with SHA-1 and shows the hash on the label and put’s it on the Windows clipboard. So if you open the LinkedIn password list in notepad, just search (CTRL+F) and paste (CTRL+V) to see if you are on the list.

Now there are two options:

1. The “I trust JP Hellemons”-way and download the attached WPF project and run it. (Less fun, but takes less time)

2. The “I don’t trust him”-way and build your own tiny app with the code provided below:

2a. Launch Visual Studio and create a new WPF project
Visual Studio New WPF Project

2b. Build your user interface with XAML in MainWindow.xaml

<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="600" WindowStyle="ToolWindow">
    <Grid Margin="0,0,-95.6,0.4">
        <TextBox Name="tb" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="your password" VerticalAlignment="Top" Width="120"/>
        <Button Content="Go" HorizontalAlignment="Left" Margin="135,11,0,0" VerticalAlignment="Top" Width="50" Click="Button_Click_1"/>
        <Label Name="lout" Content="" HorizontalAlignment="Left" Margin="190,11,0,0" VerticalAlignment="Top" Width="389" Height="31">
                <DropShadowEffect BlurRadius="3" Color="#7F000000" Opacity="0.8" ShadowDepth="3"/>
2c. Double click the Button to create a click event in the code behind

2d. Put this line at the top of the cs file

using System.Security.Cryptography;

2e. Use this code for the ButtonClick event

private void Button_Click_1(object sender, RoutedEventArgs e)
    UTF8Encoding encoding = new UTF8Encoding();
    Byte[] data = encoding.GetBytes(tb.Text);
    byte[] result; 

    SHA1 sha = new SHA1CryptoServiceProvider();
    result = sha.ComputeHash(data);

    StringBuilder returnValue = new StringBuilder();

    for (int i = 0; i < result.Length; i++)

    lout.Content = returnValue.ToString();
    Clipboard.SetData(DataFormats.Text, returnValue.ToString());

2f. Start the application and search your password’s hash in the LinkedIn password file

If you have followed the steps, it should look like this:


I am sorry about the drop shadow effect, you can remove it from the XAML by removing the ‘Label.Effect’ node with it’s content.

Don’t forget to change your LinkedIn password! Just to be sure.

good luck coding!

kick it on DotNetKicks.com Shout it

Pin on pinterest Plus on Googleplus Post on LinkedIn