Wiki Link: [discussion:1673]
Location Bug 

May 5 2009 at 4:32 PM
This article and code are very good and I'm planning on using it in several upcoming projects at my work.

I have moved the templates from using the default (read: forced) template to using any template that is applied to the window and it seems to work well.

I'm having an issue with resizing the window though. If I move the window to the top left of the screen so that it is either at location 0,0 or -,- then when I maximize the window and then restore the window it will "jump" up to a negative number that makes it almost impossible to grab the title bar. I have been looking for a solution to this but don't know the win32 hooks well enough yet to fix it. Can anyone help me out?

Coordinator
May 5 2009 at 4:51 PM
You're running into a bug in WPF. The Window class uses AdjustWindowRect in some places to figure out what the non-client dimensions should be based on the WindowStyle and then uses that for some calculations. In particular you'll see it with restore from maximize and the Top/Left properties are incorrect (in all cases the values are offset by the normal non-client dimensions).

There's not really a good way to work around this. If you just want to programmatically place the window then the best you can do is p/invoke SetWindowPos and not use Top/Left/Width/Height. For the issue with restoring the window I think you'll have to watch for WM_SIZE notifying you that the window is being maximized and then cache the data yourself to correct for what WPF does after the restore. That second workaround in particular isn't very easy to do.

The good news is this issue should be fixed in the next release of WPF.

May 5 2009 at 5:04 PM
Cool beans thanks for the quick response. By any chance is access to the window chrome going to be something built into WPF for the next release?


JoeCastro wrote:
You're running into a bug in WPF. The Window class uses AdjustWindowRect in some places to figure out what the non-client dimensions should be based on the WindowStyle and then uses that for some calculations. In particular you'll see it with restore from maximize and the Top/Left properties are incorrect (in all cases the values are offset by the normal non-client dimensions).

There's not really a good way to work around this. If you just want to programmatically place the window then the best you can do is p/invoke SetWindowPos and not use Top/Left/Width/Height. For the issue with restoring the window I think you'll have to watch for WM_SIZE notifying you that the window is being maximized and then cache the data yourself to correct for what WPF does after the restore. That second workaround in particular isn't very easy to do.

The good news is this issue should be fixed in the next release of WPF.


Coordinator
May 5 2009 at 5:35 PM
Probably not for this version; it's being considered for future ones though. If you have feedback about what should be changed if we were to put it in the framework this is the right place to voice that.


Updating...
Page view tracker