问题
As titled, in .NET 4.5 we have a font class which can give you the Height in pixes, but how about in WinRT?
Is there any API that I can use to get the pixels it uses?
回答1:
Since not even the FormattedText class exists in the .NET API for Windows Store Apps my workaround is to use a TextBlock:
TextBlock dummyTextBlock = new TextBlock();
dummyTextBlock.FontFamily = new FontFamily("Tahoma");
dummyTextBlock.FontSize = 18;
dummyTextBlock.FontStyle = FontStyle.Normal;
dummyTextBlock.FontWeight = FontWeights.Bold;
dummyTextBlock.Text = "X";
dummyTextBlock.Measure(new Size(0,0));
dummyTextBlock.Arrange(new Rect(0,0,0,0));
double width = dummyTextBlock.ActualWidth;
double height = dummyTextBlock.ActualHeight;
That gives you the height (and width) of a text how it would be displayed.
来源:https://stackoverflow.com/questions/15515162/how-to-get-the-size-in-pixels-of-a-font-in-winrt-app