如何获得WinRT应用程序中字体的大小(以像素为单位)? [英] How to get the size (in pixels) of a font in WinRT app?
本文介绍了如何获得WinRT应用程序中字体的大小(以像素为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何API我可以用它来获取它使用的像素?因为在Windows应用商店的.NET API中不存在FormattedText类应用程序我的解决方法是使用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;
这会显示文本的高度(宽度)。 >
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?
解决方案
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.
这篇关于如何获得WinRT应用程序中字体的大小(以像素为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文