WPF RichTextBox设置段落.Margin属性

WPF RichTextBox设置段落.Margin属性,wpf,richtextbox,Wpf,Richtextbox,这件事真让我抓狂。默认情况下,RichTextBox会在新段落的开头插入一行。我推测将段落边距属性设置为零将阻止这种行为,但只能看到xaml中的示例。。。我试过了 .Selection.ApplyPropertyValue(Paragraph.MarginProperty, 0.0) 但这会引发一个错误,告诉我“0”不是属性“Margin”的有效值 及 但是那没有效果…边际是一种类型-- 要添加到资源,请添加针对段落类型的样式: Style paragraphStyle = new Syste

这件事真让我抓狂。默认情况下,RichTextBox会在新段落的开头插入一行。我推测将段落边距属性设置为零将阻止这种行为,但只能看到xaml中的示例。。。我试过了

.Selection.ApplyPropertyValue(Paragraph.MarginProperty, 0.0)
但这会引发一个错误,告诉我“0”不是属性“Margin”的有效值

但是那没有效果…

边际是一种类型--

要添加到
资源
,请添加针对
段落
类型的样式:

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);

我可以发誓我也试过,但显然我没有,因为它工作得很好。
.Selection.ApplyPropertyValue(Paragraph.MarginProperty, new Thickness(0))
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);