Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:39:29+00:00 2026-05-24T06:39:29+00:00

I need to store my app window’s size/position and state when the user closes

  • 0

I need to store my app window’s size/position and state when the user closes the app and set them back when the user thereafter opens the app.

I did this easily using registry keys (is this even the best way to do?), but I’m wondering where I actually should put the code to set those properties.

I need to set them when the window first “appears” I think. But I have several methods that could be used in this case, namely:

  • Window.Show()
  • Window.Activate()
  • Window.ApplyTemplate()
  • Window.Arrange()
  • Window.ArrangeCore()
  • Window.ArrangeOverride()
  • Window.BeginInit()
  • Window.EndInit()
  • Window.Measure()
  • Window.MeasureCore()
  • Window.MeasureOverride()
  • Window.OnApplyTemplate()
  • Window.OnInitialized()
  • Window.OnRender()
  • Window.UpdateLayout()

I’m aware that most of them just are a bad idea (UpdateLayout() will be called waaaaaaay too often for instance). Idealy I’m looking for a method that will only be called once in the window’s life so that I don’t have to add a flag checking if this is the method’s first call.

so which one would be the best in this case? and why?

side question: I put the code to save the values in Window.Close() (I’m overriding the method in my MyWindow class), But I could as well have put it in Window.OnClosing() or Window.OnClosed(). Does this make any difference in my case?

side question (bis): I also have to save a datagrid’s column order, where should I put both “saving” and “loading” code in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:39:30+00:00Added an answer on May 24, 2026 at 6:39 am

    My Choice: I finally ended up putting the code to load the values from the registry in window.Show().

    the reason I did this is because of 2 things:

    1. I store the state of the window, (minimized/maximized) and the way WPF does it, I need to first set the width/height, then the maximized state (if needed), otherwise it messes up the layout. And if I don’t set the width/height first, I loose them when I de-maximize the window thereafter. So I have to do things in this order precisely: Width + height and them state. (Also, this is necessary when working with multiple screens, otherwise you loose the screen you were working on). This means that some of the methods above are impractical (the “measure” ones for instance)

    2. adding to this, if I put my code in most of the methods above-mentioned, I’ll get a bad looking effect on first display: the window will first appear with its height and width set, in the middle of the screen, and then after a small delay, the window gets maximized.

    putting the code in window.Show() managed to solve those 2 issues. I might have had the same result with one or more of the other methods, but I simply got fed-up with trying different configurations and ended up using the first one that gave me entire satisfaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store the user's password in my iphone app. When posting an
I need to store app specific configuration in rails. But it has to be:
I need to store user entered changes to a particular table, but not show
I need to store some simple properties in a file and access them from
I am developing a feature in my app where I need to store the
I have a collaborative app environment, where I need to store/log information on who
Hi guys I need some help with Apple App Store. I've an application that
I need to store products for an e-commerce solution in a database. Each product
I need to store phone numbers in a table. Please suggest which datatype should
I need to store some sensitive data by encrypting it with atleast 128 bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.