开发者

WPF broken layout

开发者 https://www.devze.com 2023-01-31 23:37 出处:网络
I have a problem with my WPF applications on certain systems. Namely, every other time when the application is started, the layout seems completely broken (unreadable text, elements and controls missi

I have a problem with my WPF applications on certain systems. Namely, every other time when the application is started, the layout seems completely broken (unreadable text, elements and controls missing parts, appearing where they're not supposed to be etc).

I've read that it has something to do with graphics drivers, but how can Microsoft expect us to work with this tech when they can't even ensure proper rendering on most systems?

I have to rewrite my latest application on Win-forms because I can't be too sure something like this isn't going to happen on my customers' computers (and given the numbers game, it certainly will at some point). Example:

WPF broken layout

This is supposed to be a gridview placed inside a groupbox. Yet, the groupbox seems completely torn apart and places it's child elements in wrong places.

Like I said, this doesn't happen every time on every system, but it happens often enough that it has become a major concern for me.

开发者_StackOverflow

Any suggestions, short of rewriting everything in Winforms (this is my first option already)?


To prevent driver issues you can switch to software rendering for Windows which are having issues with this code:

(PresentationSource.FromVisual(this) as HwndSource).CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

However, what you're seeing doesn't look like a driver issue (they're usually seen as tearing or blurring of parts of the UI). Placement of elements is handled by the layout engine running on the CPU so isn't affected by the graphics card. If it happens consistently on specific machines it's more likely a theming issue. If it doesn't happen consistently you might be running into a layout engine bug and may be able to fix the problem by using an alternate layout.


Are you sure this is a driver related problem? A driver is unlikely to screw up layout. It looks like a problem with the layout engine or possibly bugs in the theme styles on the problem machines.

I would do the following in order and check results.

  1. Use default windows theme on problem machines and check.
  2. Set target .Net framework version to a sensible one and check. I think a min of 3.5 SP1 should be good enough.
  3. Update display driver on problem machines and check.

I think you are guessing that the problem is related to display drivers. Are you certain? I use 3.5 SP1 with some pretty complicated UI running on > 200K machines without issues.

I have had one display driver related problem on NVidia drivers but thats specific to drop shadows and its properly documented on the MS connect site.

0

精彩评论

暂无评论...
验证码 换一张
取 消