The ViewBox is a very useful control in WPF. If does nothing more than scale to fit the content to the available size. It does not resize the content, but it transforms it.
Questions tagged [viewbox]
358 questions
53
votes
5 answers
SVG Scaling Text to fit container
This is likely a very simple question, but how do I get text in SVG to stretch to fit its container?
I don't care if it looks ugly from being stretched too long or high, but it needs to fits its container and be as big as possible.
Thanks

Tom
- 6,947
- 7
- 46
- 76
51
votes
4 answers
Manipulate SVG viewbox with JavaScript (no libraries)
I'm trying to alter an SVG elements viewbox in JavaScript. Basically, I'm drawing a binary search tree, and when it gets too wide, I want to alter the viewbox to zoom out so that the tree fits in the window. I'm currently using:
if(SVGWidth>=1000){
…

Andrew Clear
- 7,910
- 5
- 27
- 35
28
votes
2 answers
Stretching the items in a WPF ListView within a ViewBox
I have a frustrating problem that I would much appreciate some help with. I have a ListView within a ViewBox and I can't get the items within the ListView to stretch horizontally.
Here is the XAML:

MajorRefactoring
- 3,713
- 3
- 20
- 26
19
votes
5 answers
Making a Viewbox scale vertically but stretch horizontally
I want to make a Viewbox (or something similar) that scales only its height, and then stretches its content horizontally.
If I do this:
then I get…

Joe White
- 94,807
- 60
- 220
- 330
16
votes
5 answers
SVG viewbox height issue on ios Safari
I have noticed a strange thing on ios when using svg. The svgs seem to work fine in all other browsers, but on Safari ipad/iphone the viewbox has some weird space at the top and bottom of the svg. Has anyone else come across this and have you been…

user2541153
- 451
- 2
- 8
- 16
14
votes
3 answers
TextBlock text doesn't wrap when placed inside a ViewBox
I have a TextBlock with a long line of text which I want to wrap. I've placed the TextBlock within a ViewBox expecting the text size to change while still wrapping, however this doesn't seem to happen. The ViewBox just resizes the TextBox so that…

Sun
- 4,458
- 14
- 66
- 108
13
votes
2 answers
Aligning content in a WPF Viewbox
I have a Viewbox with Stretch=Uniform in order to not distort the content.
However, when the frame window is wider or taller than the content, the Viewbox content is always centered.
I cannot seem to find any content alignment options on the…

Jeff B
- 1,856
- 2
- 17
- 28
11
votes
1 answer
Get the size (after it has been "stretched") of an item in a ViewBox
Consider the following:
Let's say the Window is 1024x768 and the ViewBox fills the entire window,
this means the TextBox is really large on the screen.
I want to get the size of the TextBox as it is currently on the screen.
If I get DesiredSize or…

TimothyP
- 21,178
- 26
- 94
- 142
10
votes
1 answer
How to get a WPF Viewbox coefficient of scaling applied
In case we use WPF (Silverlight) Viewbox with Stretch="UniformToFill" or Stretch="Uniform" when it preserves content's native aspect ratio, how could we get knowing the current coefficient of scaling which were applied to the content?
Note: we not…

rem
- 16,745
- 37
- 112
- 180
10
votes
2 answers
Using Viewbox to scale Grid containing Labels and Textboxes
So I'm trying to build out a form that will automatically scale proportionally up and down based on the available width of the parent container, and the same column percentage ratios, like this:
There will be other surrounding content that needs to…

jhilgeman
- 1,543
- 10
- 27
9
votes
3 answers
Textbox will not stretch to fill viewbox
I want the font size of my labels and textboxes in my LOB form to grow and shrink with window resize or resolution change. To achieve this I've placed my labels and textboxes within viewboxes.
The labels and custom radio buttons behave as I expect,…

Blake Mumford
- 17,201
- 12
- 49
- 67
9
votes
2 answers
TextBlock inside a Viewbox - strange rendering
This is a question regarding a very simple construction - I have the following XAML:
My Cool Text
This is quite simple to understand.…

Jefim
- 3,017
- 4
- 32
- 50
9
votes
1 answer
Find svg viewbox that trim whitespace around
Assuming I have an svg that draws some paths, what tools should I use to find a viewbox that perfectly fits those paths so that all redundant space around is trimmed?

KwiZ
- 1,364
- 2
- 15
- 25
9
votes
2 answers
How to set ViewBox background?
I need to set the background of my System.Windows.Controls.Viewbox, but the property is missing.
How can I fix this problem?

Nick
- 10,309
- 21
- 97
- 201
9
votes
1 answer
Maintaining fixed-thickness lines in WPF with Viewbox scaling/stretching
I have a which contains some vertical and horizontal s. I want the grid to be scalable with the window size, and retain its aspect ratio, so it's contained in a .
However, I also want the lines to always…

Twicetimes
- 678
- 1
- 7
- 15