首页 文章

WPF RichTextBox设置Paragraph.Margin属性

提问于
浏览
1

这个真的让我疯了 . 默认情况下,RichTextBox在新段落开始之前插入一个额外的行 . 我收集将Paragraph Margin属性设置为零将阻止此行为,但只能在xaml中看到示例...我已经尝试过了

.Selection.ApplyPropertyValue(Paragraph.MarginProperty, 0.0)

但是这会引发一个错误,告诉我“0”不是 property “保证金”的有效值

.Resources.Add(Paragraph.MarginProperty, 0.0)

但那没有效果......

1 回答

  • 2

    保证金是Thickness类型 -

    .Selection.ApplyPropertyValue(Paragraph.MarginProperty, new Thickness(0))
    

    要添加到 Resources ,请添加定位 Paragraph 类型的样式:

    Style paragraphStyle = new System.Windows.Style { TargetType = typeof(Paragraph) };
    paragraphStyle.Setters.Add(new Setter { 
        Property = Paragraph.MarginProperty, 
        Value = new Thickness(0) });
    .Resources.Add(null, paragraphStyle);
    

相关问题