How can I make RichTextBox
with no Margin, Border, Padding etc. ? In another words to display content in the same way as TextBlock
does it ? I have tried this:
<RichTextBox Margin="0" Padding="0" Grid.Row="0" BorderThickness="0" >
<FlowDocument >
<Paragraph>LLL</Paragraph>
</FlowDocument>
</RichTextBox>
<TextBlock>LLL</TextBlock>
But the result produces is still not what I want:
There is still some space before document content (and also maybe after, on the top or bottom of the document...). How can I remove it ?
If you are interested why I need this: I trying to make H.B.'s answer to my question Create guitar chords editor in WPF to work with kerning and I don't want to have unnatural space between characters.
Edit
So it is not ControlTemplate
at least not only that because following code will produce exactly the same result (as the one on the picture above):
<RichTextBox Margin="0" Padding="0" Grid.Row="0" BorderThickness="0">
<RichTextBox.Template>
<ControlTemplate>
<ScrollViewer Padding="0" Margin="0" x:Name="PART_ContentHost"/>
</ControlTemplate>
</RichTextBox.Template>
<FlowDocument PagePadding="0">
<Paragraph Padding="0" Margin="0" >LLL</Paragraph>
</FlowDocument>
</RichTextBox>
And I thought this will be question easy to answer... Interesting observation: when I have template set and I set PagePadding="0"
on FlowDocument
it displays layout that I want in the VisualStudio designer - until I run the demo. In the demo it is wrong again... And when I close the demo it is wrong again in the designer. This is a small bug of VS or is it actually set to the right layout for a while but then something changes value of PagePadding
back to some wrong value ?
Edit#2
Daniel Rose's edited answer is also not working for me. This is XAML:
<FlowDocument PagePadding="{Binding PagePadding}">
<Paragraph x:Name="paragraph" Padding="0"
TextIndent="0" Margin="0,0,0,0" >hello</Paragraph>
</FlowDocument>
And this is in code:
public static DependencyProperty PagePaddingProperty =
DependencyProperty.Register("PagePadding", typeof(Thickness), typeof(EditableTextBlock),
new PropertyMetadata(new Thickness(0)));
public Thickness PagePadding {
get { return (Thickness)GetValue(PagePaddingProperty); }
set { SetValue(PagePaddingProperty, value); }
}
No changes to the result. Space remains.
Edit#3
After adding Two-Way binding as Daniel Rose suggested in his las edit it works. Still I don't really think it is very clear (to have dependency property because I need to keep PagePadding
at 0 value). I think it is a hack - bug workaround. If somebody has better solution please share it.
Obviously "changing PagePadding
" of FlowDocument
to 0,5
is a bug. If somebody has MSDN account it would be nice if they reported this bug.
See Question&Answers more detail:
os