跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

UIHelper.cs

34 行 · 1011 B历史下载
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows;
8using System.Windows.Controls;
9using System.Windows.Media;
10
11namespace 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}