Get XAML from WPF Custom RichTextFormat
Posted
by Erika
on Stack Overflow
See other posts from Stack Overflow
or by Erika
Published on 2010-04-09T06:54:47Z
Indexed on
2010/04/09
7:13 UTC
Read the original article
Hit count: 439
I've looked at other posts, but i cant seem to find something that works. I have a custom control WPF RichTextBox and would like to obtain the XAML from this control.
I have tried the following
//rt is the name of this particular custom richtextbox
TextRange range = new TextRange(rt.Document.ContentStart, rt.Document.ContentEnd);
MemoryStream stream = new MemoryStream();
range.Save(stream, DataFormats.Xaml);
string xamlText = Encoding.UTF8.GetString(stream.ToArray());
return xamlText;
but this doesnt seem to work :s I can access the rt.Document.Content start etc but it seems to crash there "Object Reference not set to instance of an object".
I am using the richtextbox directly from the .xaml.cs so it should be initiated and so on :s.
Any Ideas or other ways to get the XAML from a richtextbox pls? (i'm requiring the XAML cos i actually want to get the HTML.. if theres some other direct manner perhaps?)
© Stack Overflow or respective owner