dimanche 10 mai 2015

WPF adds black bar to Window

I have built a WPF application with a variable width and height (xaml height and width definition for the window is set to Auto). Once the contents of the window are loaded, the width does not (well, is not supposed to) change. The height might change as items are removed or added from the list.

The background is a gradient, not an image.

After a period where the application is idling and isn't the top-most, when switching back to the application, the window is wider as a black bar was added, extending the window to the right.
I've blurred out the content as it is unimportant here.
(Before this black bar appears, the window's width is the section with the blue gradient background)

I've added a hidden menu item to the window and when the user presses Alt the menu appears. At first, I simply added the menu and opening it caused the window to re-render as menu the item suddenly became visible and added to the window's height. As the window was re-rendered, the black bar disappeared and the window was its original width.

I tried the following solutions by adding an event where Window.OnFocus calls a function which:

  1. changes the width (adds 1 pixel and then removes 1 pixel)... but this doesn't seem to do anything.
  2. checks the width of the window. If the width is larger than the expected width, a re-render is manually called. But no dice...

What is causing this black bar to appear? How can I prevent it from happening?

The biggest problem here is that I can't seem to consistently reproduce the problem... sometimes, the application will sit open, idling in the background for the whole day and this won't happen. Sometimes, I'll go out to lunch, come back and there it is...

Aucun commentaire:

Enregistrer un commentaire