Recently in a PDF-related project, our app is running under Windows 8/WINRT. Text area does not support multiline text wrapping because of some technical limitations of the third-party libraries used. So we need to implement the self-wrapping, the key to achieve this function is to know how to calculate a character, a word in the specified font and font size under the premise of how wide. In fact, we can use Uielement.measure () to achieve. The specific implementation code is as follows:
Private Static DoubleMeasureString (stringTextDoubleFontSize =7.0) { varTextBlock =NewTextBlock (); Textblock.text=text; Textblock.fontsize=fontSize; Textblock.fontfamily=NewWindows.UI.Xaml.Media.FontFamily ("Microsoft Yahei"); Textblock.measure (NewSize (Double.maxvalue, Double.maxvalue)); returnTextblock.actualwidth; }
How the Windows Store app calculates the width of characters