What is the best substitute for FlowDocument in Silverlight? - silverlight

I'm porting an application from WPF to Silverlight and was saddened to read of the lack of FlowDocument support.
What is the best way in Silverlight then to display text with markup?
I just need the basics, e.g.
bold
italic
hyperlink
colors
font sizes
Added:
I don't mean a RichTextBox (as in the Vectorlight demo) but a way to format text on the application surface itself, like I can do with FlowDocument in WPF:
(source: deviantsart.com)

In Silverlight 3 Vectorlight's Free RichTextBox can do a pretty good job of what you need using HTML.
In Silverlight 4 you have the option of using the RichTextBox to represent your content.

If you do get something like that up and running, msg me and maybe we can collaborate on bringing my "BindableFlowDocument" into the world of Silverlight. ;)
edit - wow, I must have gotten mixed up - my original answer was way off

Inline with the comments of SL4 RC's RichTextBox (RichTextArea, circa SL4 Beta), and with your example of importing marked up text, the SL4 RC RichTextBox will allow for an import of XAML formatted text - like string richText = MyRichContent.Xaml; on this page: http://timheuer.com/blog/#richtextbox. Details are listed here: http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.xaml(VS.96).aspx.

Just use the RichTextBox in Silverlight 4.0

Related

Custom Tooltip Formatting

I am working in plain old native C on Windows. No other platforms, no C++. (Yes, I'm a dinosaur.)
I am trying to find an example of what I think of as an "owner draw tooltip control" but that does not appear to exist. At least not for the standard Windows tooltip control. I have tried to search for a library or source that implements a custom tooltip control, but all I can find is things that extend controls in .NET (or in other environments that are not where I am working.)
My hope is to support markdown (or something like it) for the text in the tooltip window. Mostly, I want to clearly differentiate the title from the content, and have some limited formatting of the content (bold, italics, color, and columns, mostly.)
I don't expect a full solution here, I am just hoping that someone else has already found a solution and can point me to where they found it. Please?
Tooltips cannot be owner drawn, but they can be "custom drawn".
Custom drawn Win32 controls allow you to override the built-in drawing by receiving and responding to the NM_CUSTOMDRAW notification. You can read about custom draw here.
You can refer to the specific documentation on the tooltip control, see:
NM_CUSTOMDRAW (tooltip) notification code
Finally, here is a good tutorial demonstrating the whole thing in C.

WPF - RichTextEditor

im searching for a Usercontrol that generates XAML-Code (Flowdocument Code)
For a Bold Text -> <Paragraph><Bold>Text</Bold></Paragraph>
You may want to have a look at the RichTextBox in the Extended WPF Toolkit - http://wpftoolkit.codeplex.com/wikipage?title=RichTextBox
I haven't tried it, but according to the documentation it has a XamlFormatter as well.
From what kind of object do you want to generate the Xaml-code?
If it is a TextBox content you could try to use some Converter classes.

Can not get image information from Silverlight RichTextEditor

I'm trying to use the Silverlight RichTextEditor in our website. Now we'd like to translate the content in richtextbox into HTML code to save and load.
However, as we know, the richtextbox control does not support the UIelements output. When we insert an image in the richtextbox, the richtextbox would use a inlineUIcontainer to show this image. The property Richtextbox.xaml does not include any information about the image. It just shows the code like "".
Does anyone have this problem and handle it before?
RichTextBox.Xaml strips out a lot of things, as a security safeguard (more for the setter than the getter as far as I recall, but it does it both ways so there are no round-trip surpises).
I recommend looking at the XAML Serializer written by David Poll on his blog (here: http://www.davidpoll.com/2010/07/25/to-xaml-with-love-an-experiment-with-xaml-serialization-in-silverlight/ ) as it can serialize RTB awesomely well (it's in fact one of the test cases he shows). David was a PM on the Silverlight XAML Parser in SL4, so he knows an awful lot about XAML.
But be careful when setting the .Xaml property, as you could mistakenly end up spinning up InlineUIContainer elements which load resources into your AppDomain that you don't want in there, so make sure you control the inputs or you strip them yourself very carefully.

Serializing WPF RichTextBox to XAML vs RTF

I have a RichTextBox and need to serialize its content to my database purely for storage purposes. It would appear that I have a choice between serializing as XAML or as RTF, and am wondering if there are any advantages to serializing to XAML over RTF, which I would consider as more "standard".
In particular, am I losing any capability by serializing to RTF instead of XAML? I understand XAML supports custom classes inside the FlowDocument, but I'm not currently using any custom classes (though the potential for extensibility might be enough reason to use XAML).
Update: I ended up going with RTF because of its support for text-encoded embedded images. XAML doesn't seem to include image data in its encoding, and XamlPackage encodes to binary, so RTF just works better for me. So far I haven't noticed any lack in capability.
If all your users are doing is typing in the RichTextBox and doing character formatting, RTF is as good as XAML. However there are many FlowDocument capabilities you may expose in your UI that are not convertible to RTF.
Here are some examples of FlowDocument (and RichTextBox) features that are not expressable in RTF or are implemented differently:
A Block can have an arbitrary BorderBrush, including gradient brushes with stops, VisualBrush
A Section has the HasTrailingParagraphBreakOnPaste property
Floater / ClearFloaters is implemented differently
Hyphenation can be enabled/disabled per block, not just per paragraph
WPF Styles and ResourceDictionaries can be included in the Resources property
Arbitrary WPF UI such as bound CheckBoxes, etc, can be embedded inside the RichTextBox and can be cut-and-pasted from other windows.
For example, suppose you want to allow users to drag or cut/paste in a "current date/time" field into your RichTextBox that would always show the current date and time. This could be done by adding a second read-only RichTextBox that has the InlineUIContainer and the already-bound control. This even works when cutting and pasting from other applications and does not require custom controls.
Another consideration is that the code to convert between FlowDocument and RTF is relatively complex so it may have lower performance than going with XAML. Of course loose XAML doesn't include images and such - for that you need to use XamlPackage. I store my XamlPackage in the database as a byte[], but you can also choose to Base64 encode it for storage as a string.
The bottom line is that it really depends on whether you want the user to be able to use features not available in RTF. Even if your application doesn't include tools to generate FlowDocuments that use these features, it is possible to cut-and-paste them from other applications.
Be aware that in Wpf RichTextBox's method called TextRange.Save has a bug whereby it loses any end of line terminator. Microsoft will not fix.
https://connect.microsoft.com/WPF/feedback/ViewFeedback.aspx?FeedbackID=478640&wa=wsignin1.0#tabs

Printing/Previewing WPF RichTextBox - ApplicationCommands.PrintPreview?

I'm really loving the WPF RichTextBox, and all of the out-of-the-box functionality it comes with...but printing is something that I'm having trouble with. I can print (from code) using a PrintDialog and passing in my RichTextBox as a Visual (or by using the "Document").
But my question is, is there a simple way to use the application commands:
ApplicationCommands.Print
ApplicationCommands.PrintPreview
With a WPF RichTextBox? Also, how would I go about letting the user change the page layout and such?
Take a look at http://blogs.msdn.com/llobo/archive/2007/01/24/printing-richtextbox-content-find-the-idle-printer.aspx

Resources