XAML to HTML converter - silverlight

I have a requirement to save emails written in a RichTextBox to a database. Obviously, I would like to persist the formatting to the DB and send out HTML emails. However, this requires converting XAML to HTML which will be stored and then converting back if they are reloaded from the DB.
I have tried out the XAMLtoHTML converter. The problem I am getting is that the converter only works partially. It sets up all the formatting correctly in HTML but the text part is missing. I have followed this post:: XAML to HTML Conversion - WPF RichTextBox and had the same error but adding the tags didnt solve the problem.
Has anyone got experience with XAML to HTML conversions? Thanks

Consider using this free HTML Editor for silverlight instead. Html RichTextArea Control (Silverlight 4 Only).
You then load and save HTML and not bother with Xaml at all. Just be careful with the fontsizes, last time I looked only px sizes worked, pt sizes were not supported. You may want to fiddle with the samples font drop down so that the actual value is 1.33 the displayed size.

Related

FixedPage and Grid.IsSharedSizeScope

I am trying to save an WPF UI to an XPS file stream.
Everything works as it should but there is one problem with Grid that use Grid.IsSharedSizeScope. Although when WPF UI rendered the column sizing is honored it is ignored when the UI saved to XPS so there is no equal column sizing.
Does anybody know why this could be happening and if there is a workaround ?
I wrote an application that generates various printed reports, which involves programmatically creating XAML controls and adding them to a FlowDocument. I remember hitting an issue where "Auto" widths are ignored, so had to use numeric or "star" values. Rendering the exact same XAML "to screen" worked fine.
Perhaps your shared size scope problem is related to the same problem. I remember reading about this "known issue" way back when I wrote this stuff, but don't have a link sorry.
I've just looked at my reporting code and didn't find anywhere that I've used shared size scopes (which is odd given their tabular nature), so perhaps I hit the same issue at the time.

Images and HTML in WPF app

I have a WPF application where I have a column that should display one of the following:
If images are returned, display the images.
If a HTML text is returned, render the HTML table within the cell.
Can someone please tell me how I can do that?
For HTML, you may refer this link - http://pdgp.wordpress.com/2008/05/31/show-html-formatting-in-gridview-cells/
For showing Image, you may refer here - http://msdn.microsoft.com/en-us/library/2ab8kd75.aspx
Hope this helps.
[Update for Winforms DataGridView]
In order to display HTML, the only choice would be to override the Paint method I suppose. Alternatively, you may think of hosting a WebBrowserControl.
How to: Host Controls in Windows Forms DataGridView Cells:-
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx

Can the WPF RichTextBox display binary picture content?

I am trying to display an RTF file (that was created in a legacy system) in a new WPF application and have run into some difficulty. The old RTF file contains a picture formatted as a binary jpegblip which, when read into the RichTextBox, causes this exception:
Unrecognized structure in data format 'Rich Text Format'. Parameter name: stream
I reduced the file down to the bare minimum to isolate the problem and ended up with the following opening line (the binary data has been removed for this post):
{\rtf1{\pict\picw2700\pich2700\picwgoal2700\pichgoal2700\jpegblip\bin9889
This still caused an exception so I converted the binary data to hex and created a new file with the opening line:
{\rtf1{\pict\picw2700\pich2700\picwgoal2700\pichgoal2700\jpegblip
The file with the hex data in it was displayed correctly by the control.
Has anyone been able to load a file containing binary picture data into the RichTexBox control, or failing that, is there a difinitive statement as to what the RichTextBox supports from the RTF specification?
I'm not even sure Microsoft knows what RichTextBox implements. Their idea of RTF floats around untethered in space. See MS Word, Wordpad, the numerous legacy Rich Edit controls, etc.
This has some comments that talk about using the COM objects in your .NET code, which are somewhat predictable, but again Microsoft doesn't specify what parts of the spec they follow. Broken tables in RichTextBox control (word wrap) - you can use these in WPF if you wrap them properly.
If you just have to display the document, you might ask if all your users will have Word. Then you might be able to embed the Word document viewer, and presto, problem solved. It's an easy dependency to add if your software is used in an office.
I would probably read up on that format until I knew how it worked. Then in my program, I would read the RTF file into a buffer, grab the raw object data, translate it somehow, replace those objects with updated ones, then pass it to the control.
For me, this code works fine. I can even pull it from a database table too.
<RichTextBox Height="100" HorizontalAlignment="Left" Margin="306,30,0,0" Name="rtfMain" VerticalAlignment="Top" Width="200" />
rtfMain.Selection.Load(new FileStream(#"C:\temp\document.rtf", FileMode.Open), DataFormats.Rtf);

Getting rid of autogenerated html

When I create a Global Data Type for localizable content in user controls I run into the problem that C1 always surrounds plain text with
<p></p>
I don't want that if the content is just meant to be inside a link for example, but still has to contain html. Even if I use the code view of the Visual Editor, C1 will readd the tags e.h. if I translate the data.
Is there a way to stop C1 from automagically adding html to my string data when using the visual editor?
I suggest you leave the editor as it is and keep on storing your html as valid xhtml documents, and instead handle this when rendering. Not having custom features/design permeate the way you store data could also be a plus in the long run.
One way to achieve this is with XSLT as described in this article "How can I modify the HTML from the Visual Content editor?" - you can also do this with C#.
There has been a few reports of this undesired behavior, but unfortunately its by design. You could argue if ts Composite C1's fault or the underlying TinyMCE editor, but maybe you can tweak the configuration of it. Or wrap the functions that output the content with a xslt-template that will strip out the p's.
See these discussions for further explanations.
TinyMCE Config Change - Force P False
Visual editor adding p tag automatically

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.

Resources