Iris Classon
Iris Classon - In Love with Code

XAML/WinRT/Metro App Q n’ A: How to set border to TextBlock height and width?

Answered this question on Stackoverflow recently. To let a parent element of a textblock have the same size and width as the textblock a simple wrap with width and height set to auto wont do it. But why would you want to do such a thing anyway?
Well you might:

  1. Want to follow the recommendation to localize your app, which means that the text can differ in size based on the language- and setting a fixed size might cut the text of,- or allow to much space.
  2. Want to be able to dynamically change the text and keep (for example) the border snug
  3. or something else

One way to solve this:
[sourcecode language=“XML”]
//

//
[/sourcecode]

Comments

Leave a comment below, or by email.
Scruff.R
9/15/2012 4:31:00 PM
I have tried something similar (bind FontSize to ActualHeight of TextBox) but in Metro/Windows store apps this does not seem to work. 
AcutalHeight reports 0 at the time when the binding is executed. 
Later on ActualHeight (e.g. in GotFocus handler) reports correct values.

I have not yet found a XAML-only solution to bind FontSize to Control.Height. 


Last modified on 2012-07-11

comments powered by Disqus