Вы можете попытаться использовать атрибут LineStackingStrategy = "BlockLineHeight", а также конвертер для атрибутов LineHeight и конвертер для высоты TextBlock.Это пример кода преобразователей
// Height Converter
public class FontSizeToHeightConverter : IValueConverter
{
public static double COEFF = 0.715;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (double)value * COEFF;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
// LineHeightConverter
public class FontSizeToLineHeightConverter : IValueConverter
{
public static double COEFF = 0.875;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return double.Parse(value.ToString()) * COEFF;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Коэффициент, используемый на преобразователях, зависит от используемых семейств шрифтов (Baseline и LineSpacing):
<TextBlock Text="ABC" Background="Aqua" LineStackingStrategy="BlockLineHeight"
FontSize="{Binding ElementName=textBox1, Path=Text}"
FontFamily="{Binding ElementName=listFonts, Path=SelectedItem}"
Height="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource FontSizeToHeightConverter1}}"
LineHeight="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Converter={StaticResource FontSizeToLineHeightConverter}}"/>
![sample with params Coeff = 0.7](https://i.stack.imgur.com/0WhQR.png)
Лучшее решение состоит в том, чтобы найти способ расчета Coeff на основе параметров Baseline и LineSpacing из FontFamily.В этом примере (пользовательский интерфейс Segeo) Coeff of Height = 0,715 и LineHeight = 0,875 * FontSize.