I have an rtf of which the layout displays perfect when I open it in word, but when I try to open it in the richtextbox in my wpf app, the layout is off, and I would love to keep it the same. Is there a way of doing this? A different way of reading the file?
Here is the code I use to load the rtf file
openFile.InitialDirectory = @"C:\";
openFile.Filter = "Text files (*.rtf)|*.rtf|All Files (*.*)|*.*";
openFile.RestoreDirectory = true;
openFile.Title = "Select Script";
if (openFile.ShowDialog() == true)
{
string originalfilename = System.IO.Path.GetFullPath(openFile.FileName);
TextRange range;
FileStream fStream;
if (openFile.CheckFileExists)
{
range = new TextRange(rtfMain.Document.ContentStart, rtfMain.Document.ContentEnd);
fStream = new FileStream(originalfilename, System.IO.FileMode.OpenOrCreate);
range.Load(fStream, DataFormats.Rtf);
fStream.Close();
}
}
and this is the xaml
<RichTextBox IsReadOnly="True" x:Name="rtfMain" HorizontalAlignment="Left" Width="673" VerticalScrollBarVisibility="Visible"/>
here is how the orginal looks like
And this is how it looks in the richtextbox in wpf
RichTextBox
displays rtf. I see there is a margin from left for a first paragraph, which seems to be ignored. Maybe it's because you not usingSelectAll()
beforeLoad
? – Sinatr