1

What's the correct pattern to resize controls when a font size changes?

For example, I used the WPF designer to make a form, and placed UI elements from the toolbox. Late in the game I got the requirement that the font size of every UI element needs to be configurable, so now I'm thinking there has to be a better way to resize controls when the font size changes. Right now I'm doing alot of code behind calculations on Margin properties.

2 Answers 2

5

For such cases I usually place my control inside Grids and StackPanels, this way font size won't affect the layout, everything will be stretchable.

Never place controls on the Window using absolute coordinates.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 this Eugen is right this is the base design rule in WPF (or similar). Consider that even later on you might get requirement for localization of your GUI. Grids, DockPanels, StackPanels and especially WrapPanels will save you!
2

Make sure your Height and Width on the controls are set to Auto. When you use the designer/toolbox to add controls it usually provides a static height/width. If you type the tag in the XAML editor you get the control default which is usually Auto.

You'll notice the black diamond in the property window next to the attributes that are changed from their default value. You can right click and choose reset value to clear the attribute from your XAML and see what the default value is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.