| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Globalization; |
| 4 | using System.Linq; |
| 5 | using System.Text; |
| 6 | using System.Threading.Tasks; |
| 7 | using System.Windows; |
| 8 | using System.Windows.Controls; |
| 9 | using System.Windows.Media; |
| 10 | |
| 11 | namespace UI.Base |
| 12 | { |
| 13 | public static class UIHelper |
| 14 | { |
| 15 | ///<summary> |
| 16 | /// |
| 17 | ///</summary> |
| 18 | ///<param name="textBlock"></param> |
| 19 | ///<returns></returns> |
| 20 | public static Size MeasureString(TextBlock textBlock) |
| 21 | { |
| 22 | var formattedText = new FormattedText( |
| 23 | textBlock.Text, |
| 24 | CultureInfo.CurrentCulture, |
| 25 | FlowDirection.LeftToRight, |
| 26 | new Typeface(textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch), |
| 27 | textBlock.FontSize, |
| 28 | Brushes.Black, |
| 29 | new NumberSubstitution()); |
| 30 | |
| 31 | return new Size(formattedText.Width, formattedText.Height); |
| 32 | } |
| 33 | } |
| 34 | } |