mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-19 17:11:28 -07:00
25 lines
739 B
C#
25 lines
739 B
C#
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
|
|
namespace Bloxstrap.UI.Utility
|
|
{
|
|
static class Rendering
|
|
{
|
|
public static double GetTextWidth(TextBlock textBlock)
|
|
{
|
|
return new FormattedText(
|
|
textBlock.Text,
|
|
CultureInfo.CurrentCulture,
|
|
FlowDirection.LeftToRight,
|
|
new Typeface(textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch),
|
|
textBlock.FontSize,
|
|
Brushes.Black,
|
|
new NumberSubstitution(),
|
|
VisualTreeHelper.GetDpi(textBlock).PixelsPerDip
|
|
).Width;
|
|
}
|
|
}
|
|
}
|