答案 0 :(得分:-1)
以下解决方案取自以下答案: Calculate Font baseline in WinRT
private double GetBaselineOffset(double size, FontFamily family = null, FontWeight? weight = null, FontStyle? style = null, FontStretch? stretch = null)
{
var temp = new TextBlock();
temp.FontSize = size;
temp.FontFamily = family ?? temp.FontFamily;
temp.FontStretch = stretch ?? temp.FontStretch;
temp.FontStyle = style ?? temp.FontStyle;
temp.FontWeight = weight ?? temp.FontWeight;
var _size = new Size(10000, 10000);
var location = new Point(0, 0);
temp.Measure(_size);
temp.Arrange(new Rect(location, _size));
return temp.BaselineOffset;
}
答案 1 :(得分:-2)
我设法通过HACK类型的解决方案解决这个问题。我的主要要求是为某些文本预留空间。我使用了固定字体和每个“空格”所需的计算空间。一旦我知道这一点,其余的都是微不足道的。