WPF RichTextBox设置Paragraph.Margin属性

时间:2013-07-20 00:06:19

标签: wpf richtextbox

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

.Selection.ApplyPropertyValue(Paragraph.MarginProperty, 0.0)

但是这会引发一个错误,告诉我'0'不是属性'Margin'的有效值

.Resources.Add(Paragraph.MarginProperty, 0.0)

但这没有效果......

1 个答案:

答案 0 :(得分: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);
相关问题