There is a RichTextBox with Paragraph inside it. How to change margin of the inner paragraph? There is no such property. Setting of RichTextBox.Padding to "-12,0" helps, but looks like an ugly hack.
问问题
896 次
4 回答
2
默认情况下,RichTextBox 的根边框元素将有一个边距 (12,0,12,0),因此默认情况下会添加左侧和右侧的空间。如果要更改行为,则必须自定义 RichTextBox 模板本身。
您可以使用此模板并避免在左右添加额外的边距。
<ControlTemplate TargetType="RichTextBox">
<Grid Background="Transparent">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<ContentControl x:Name="ContentElement" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
</ControlTemplate>
问候, 毛伊
于 2014-12-02T11:44:30.370 回答
1
另一个黑客:(至少对于剩余边距:)
<Paragraph xml:space="preserve">
Hi from Paragraph
Hi from Paragraph 2
</Paragraph>
于 2014-01-01T03:40:46.020 回答
1
您只需要设置段落的属性 TextIndent。我将向您展示一个示例:
<RichTextBox>
<FlowDocument>
<Paragraph TextIndent="6"><Run Text="Paragraph 1"/></Paragraph>
<Paragraph TextIndent="12"><Run Text="Paragraph 2"/></Paragraph>
<Paragraph TextIndent="18"><Run Text="Paragraph 3"/></Paragraph>
<Paragraph TextIndent="24"><Run Text="Paragraph 4"/></Paragraph>
</FlowDocument>
</RichTextBox>
这将导致:
于 2014-10-25T09:04:11.300 回答
1
这个选项怎么样:锁也很难看,但仍然:
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<RichTextBox>
<Paragraph>
<InlineUIContainer>
<TextBlock x:Name="tbMargin" Margin="100,0,0,0"></TextBlock>
</InlineUIContainer>
Hi from Paragraph
</Paragraph>
</RichTextBox>
</StackPanel>
于 2013-12-09T20:32:42.217 回答