2

I am creating a WPF desktop application with MVVM.

I have used Behavior to store the window state behavior. I want some dialogs to store the setting between application sessions. But I want some dialogs to show at last opened place for the application session, but when application is restarted the diloag must come center owner.

I can have a a flag in WindowStateSettings class to store that it is a temporary setting and will be flush at application exit. But how could I remove a specific user setting. Or there is any setting that persist for application session. I cant use static class to store the data as this behavior class doesn't share data between two dialogs.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Mohit Vashistha
  • 1,824
  • 3
  • 22
  • 49
  • You can use project settings for this, Here are few links which explains how to achieve this - http://blogs.msdn.com/b/patrickdanino/archive/2008/07/23/user-settings-in-wpf.aspx http://khason.net/blog/quick-wpf-tip-how-to-bind-to-wpf-application-resources-and-settings/ http://joshsmithonwpf.wordpress.com/2007/12/27/a-configurable-window-for-wpf/ Also look at this SO question for other options - http://stackoverflow.com/questions/3784477/c-sharp-approach-for-saving-user-settings-in-a-wpf-application/3784591#3784591 – akjoshi Jul 23 '12 at 15:49

1 Answers1

0

If you want to use the built-in settings mechanism in .NET, you can change the settings all you want while the application is running and then just never call Save() to persist the settings to disk.

Make your default location be something impossible, like (-1,-1).

Then, when showing the form, check the current setting for that form. If the value is (-1,-1) then show center. Otherwise, show it at the coordinates stored.

As long as you do not call Save() after changing the settings, it'll go right back to (-1,-1) the next time the application launches.

You also then have the flexibility to allow the user to save their layout, so that the windows will open up in the same locations next time. You'd achieve that by simply calling Save() on the settings.

dodexahedron
  • 4,584
  • 1
  • 25
  • 37