该TextBlock元素处理LineHeight得很好,允许文本完全显示,而不会剪切.但是,我想将其更改TextBox为便于编辑文本,这是我的麻烦开始的地方.
在TextBlock显示文字是这样的:
在TextBox显示文字是这样的:
我试图摆弄ClipToBounds和Clip属性,但它只在元素内剪辑,不会扩展到边界之外.
LineHeight需要将该属性设置为低以调节线之间的差距,因此不能进行更改.
我也尝试过Padding,但它只是这样做
如果这是唯一的解决方案,那我就会走开,聆听按键并相应地更改文本,但这似乎是很多工作,我不认为这是一个很好的解决方案,所以这是我的浓缩题:
如何使TextBox剪辑文本尽可能不像TextBlock它一样?
private static Style GetFontTextBlock()
{
var style = new Style();
style.Setters.Add(new Setter(TextBlock.LineStackingStrategyProperty, LineStackingStrategy.BlockLineHeight));
style.Setters.Add(new Setter(TextBlock.IsHyphenationEnabledProperty, true));
style.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));
style.Setters.Add(new Setter(Control.BorderBrushProperty, null));
return style;
}
public static Style GetHeadline()
{
// ApplyFont sets the Control.FontFamilyProperty to Geogrotesque Condensed Regular.
// It's a purchased font so I can't supply it, …Run Code Online (Sandbox Code Playgroud)