1

I have a WPF application that should scale it's UI to fit the full screen - in different aspect ratios. I'm using grids for some of it, but that doesn't scale the font, and a ViewBox to scale a TabControl, but that distorts the text by changing it's aspect ratio.

Does anybody have an alternative that scales the geometry of controls, and the font size of the text, but keeps the same aspect ratio for the font?

I've been searching for a while but nobody seems to have answered this exact issue.

This issue seems to suggest I could write something myself from scratch, but I don't see any implication I can do get control of the font scaling: Making a Viewbox scale vertically but stretch horizontally

Community
  • 1
  • 1
O'Rooney
  • 2,878
  • 2
  • 27
  • 41

2 Answers2

1

WPF does indeed have that control... it's called a Grid. Most WPF developers design applications where controls will automatically grow to fill the size of the Window while maintaining the same font size and aspect ratio. If you want a particular part of it to enlarge itself as the Window enlarges, then use a ViewBox for that part... not the whole Window.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Thanks for the suggestion, but I am already using a grid, which does NOT scale the fonts as I asked, and a ViewBox to scale a TabControl, which scales the fonts but distorts their aspect ratio. – O'Rooney Sep 15 '13 at 20:12
0

My own solution is primitive but does work to some extent.

To define control geometry, use grids with fractional width/heights, and other controls sizing to fit their content.

Calculate font scaling from the window's actual height divided by it's design height.

Set font size at the window level to designed size * scaling.

Problems:

  • have to hard code the original design height as there doesn't seem to be any way to get this from the XAML
  • have to hard code the original designed font size, ditto.
  • doesn't scale padding or margins, so proportions still tend to get a bit wonky.
  • if you want different font sizes, have to write code for all of the different controls.

WPF really makes this difficult IMO: it has scalable, resolution independent elements, but not much to actually help you build scalable user interfaces.

O'Rooney
  • 2,878
  • 2
  • 27
  • 41
  • hi, i have similar requirement to develop a WPF app for 10' 15' and 22' inch monitor.and it should be fit to scale . can you please share some code example how to achieved this UI scaling? – Kamlendra Sharma May 29 '16 at 18:58
  • I no longer work at this job so I don't have access to the code. But, I think I gave you a lot of clues. Create grids using fractional widths and heights for the rows and columns (the asterisx or * notation). Then write some code that at startup sets the font size for the window to original font size * currentheight / designheight. – O'Rooney May 31 '16 at 22:38