WPF application displays differently in Windows 7 and Windows 10
-
Hi :) I have a WPF project working fine in Windows 7, but which has a completely changed layout, when the same project is executed under Windows 10. Do any of you have experiences with this issue? I have found out that WPF loads the current theme/skin from the OS, and that this may be the cause of the skewed layout, but I haven't been able to find any whitepapers or guides with information on how to work around this problem. It is a basic Grid with Stack Panels and Labels in it, if that helps. Any help/ideas/links would be much appreciated :thumbsup: Kind regards - Jakob
-
Hi :) I have a WPF project working fine in Windows 7, but which has a completely changed layout, when the same project is executed under Windows 10. Do any of you have experiences with this issue? I have found out that WPF loads the current theme/skin from the OS, and that this may be the cause of the skewed layout, but I haven't been able to find any whitepapers or guides with information on how to work around this problem. It is a basic Grid with Stack Panels and Labels in it, if that helps. Any help/ideas/links would be much appreciated :thumbsup: Kind regards - Jakob
Hi Jakob, I had experience with this in the past, but visual changes between two OS versions were usually minor. What do you mean by "completely changed layout"? Can you please elaborate? As you pointed out, issue is (probably) about the styles and templates. By manually setting the whole style (with template etc.), you should be able to ensure same visual appearance on any (compatible) OS.
-
Hi Jakob, I had experience with this in the past, but visual changes between two OS versions were usually minor. What do you mean by "completely changed layout"? Can you please elaborate? As you pointed out, issue is (probably) about the styles and templates. By manually setting the whole style (with template etc.), you should be able to ensure same visual appearance on any (compatible) OS.
Hi Jimmson Thank you for replying. I have been isolating diffent parts of our code, to find the culprit. We are basically building a custom WPF control runtime, to use it for printing, but since it is never shown on the UI, but sent off to the printer, the WPF framework doesn't perform lay-out on the control. I understand, that these lines in the code I am trying to get to work on WIN10, are responsible for enforcing the layout functionality in a non-visible control:
fixedPage.Measure(sizeOfCustomControlToPrint);
fixedPage.Arrange(new Rect(new Point(), sizeOfCustomControlToPrint));
fixedPage.UpdateLayout();if I comment these out in WIN10, it seems to be working, but I would really like to understand why. Maybe there is a bug in the WIN10 implementation...? :confused:
-
Hi Jimmson Thank you for replying. I have been isolating diffent parts of our code, to find the culprit. We are basically building a custom WPF control runtime, to use it for printing, but since it is never shown on the UI, but sent off to the printer, the WPF framework doesn't perform lay-out on the control. I understand, that these lines in the code I am trying to get to work on WIN10, are responsible for enforcing the layout functionality in a non-visible control:
fixedPage.Measure(sizeOfCustomControlToPrint);
fixedPage.Arrange(new Rect(new Point(), sizeOfCustomControlToPrint));
fixedPage.UpdateLayout();if I comment these out in WIN10, it seems to be working, but I would really like to understand why. Maybe there is a bug in the WIN10 implementation...? :confused:
-
Have you tried to display this FixedPage in UI to see whether the problem actually is in the FixedPage, or in your custom WPF control runtime?
Great idea... It's off to the code-cave! :thumbsup: :-D
-
Hi :) I have a WPF project working fine in Windows 7, but which has a completely changed layout, when the same project is executed under Windows 10. Do any of you have experiences with this issue? I have found out that WPF loads the current theme/skin from the OS, and that this may be the cause of the skewed layout, but I haven't been able to find any whitepapers or guides with information on how to work around this problem. It is a basic Grid with Stack Panels and Labels in it, if that helps. Any help/ideas/links would be much appreciated :thumbsup: Kind regards - Jakob
You're doing "measures" and "arranges" based on a control whose dimensions you have not ascertained. What was a number in Win 7 could now be a NAN in Win 10, or vise-versa. You use the debugger, "Live Visual Tree" and "Live property view" to confirm the heights and width are inherited / accessed as expected.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects
-
You're doing "measures" and "arranges" based on a control whose dimensions you have not ascertained. What was a number in Win 7 could now be a NAN in Win 10, or vise-versa. You use the debugger, "Live Visual Tree" and "Live property view" to confirm the heights and width are inherited / accessed as expected.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.' ― Confucian Analects
Good points. Thanks, Gerry :thumbsup: :)