This one turned out to be a lot simpler than I had expected. As a result, the code isn't available. You'll have to do it yourself.
The question was one of attaching a property of our UI (say, the checked property of a MenuItem) to one of the clever Resources.Properties values that are taken care of for us by VS 2005. In our Scribble application, there are a few things we'll want to persist between sessions (on a per-user basis) such as toolbar visibility and window size (and maybe window state).
First, we add values to the Settings class for the values we would like to persist. You can do this in the properties for the project or by double-clicking on the Settings.settings class (does anyone know why there are so many ways to accomplish the same task in VS2005?).
I added MainWindowWidth and MainWindowHeight as user-scoped, integer values. I also added InkToolbarVisible, FileToolbarVisible, and StatusbarVisible as bool values. I set these with reasonable defaults.
Now, we have to hook these settings up to the properties of the UI. We will use similar syntax to how we hooked up our Exit command.
For the window size, we set width and height like this:
<Window Height="{Binding Source={x:Static scribble:Properties.Settings.Default}, Path=MainWindowHeight, Mode=TwoWay}" Width="{Binding Source={x:Static scribble:Properties.Settings.Default}, Path=MainWindowWidth, Mode=TwoWay}">
For the toolbar and statusbar visibility, we bind the IsChecked property (since that's where the toolbar and statusbar get their visibility). We set all three values with the same syntax:
<MenuItem Header="_File Toolbar" x:Name="_viewFileBar" IsCheckable="True" IsChecked="{Binding Source={x:Static scribble:Properties.Settings.Default}, Path=FileToolbarVisible, Mode=TwoWay}"/>
That's it, except for saving the values when the application closes. To to this, we override the Windows OnClosing method in the Scribble.xaml.cs file. Here are the contents:
protected override void OnClosing(CancelEventArgs e) { Properties.Settings.Default.Save(); base.OnClosing(e); }
Compile and run a few times, changing the toolbar visibility and the window size. The application will remember these values each time you run.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.