Strings with formatting in SQL to Silverlight App need help - silverlight

I am moving all strings in my Silverlight app to the db, but am having some trouble keeping the formatting. Really the only issue is for paragraph sized strings, which in the app used to keep the paragraph sized right and spacing between paragraphs. Unfortunately now that I need to bind the textblock I have to use it's text property instead of just sandwiching the text between the opening and closing tags to let the formatting do its thing. The result is that the formatting is displayed as part of the text now and isn't applied. Does anyone know how to get around this? I've tried adding Char(13), \n, different configurations of ' ', it all displays exactly how I enter it. Any ideas?

You need to use a rich text box control. Here are some options for Silverlight: What is the best substitute for FlowDocument in Silverlight?

Silverlight uses \r for line breaks and in SQL Server line breaks are \r\n. There is a nice value converter in this post that converts between the two.

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.

Why are there strange backspace characters in my WPF datagrid?

Our software uses the DataGrid throughout its user interface for displaying editable lists. While editing some metadata, I wanted to remove the text in a particular column for many rows. This is pretty quick if you get into the rhythm of F2-Backspace-Enter, F2-Backspace-Enter, F2-Backspace-Enter….
Things don’t go quite so well if you miss the F2 part of the pattern and just press Backspace-Enter on a cell. The WPF DataGrid will actually replace the contents of the cell with the backspace character. Depending on how you look at your string, this might show up as 0×08, , \u0008, or \b.
What on earth?
This CodePlex post confirms a bug in the DataGrid and includes some workarounds. On our end, the current fix is simply to ignore strings that have a backspace character in them. This way they don’t end up in the XML, which is good because in XML 1.0 the backspace is an illegal character.
See also this Microsoft Connect issue.

Incorrect bidi behaviour in WPF?

I experience strange things when setting the "Language" property in WPF:
Set FlowDirection to "RightToLeft" on a Window or textbox/textblock
Set the Language property to "fa-IR"
Set the text to one of the sample texts below (A, B)
A. This text does not render correctly in WPF 3.5:
فاکس: ‎+44 1908 215040
It works with WinForms and Silverlight. Note that it contains a 'LEFT-TO-RIGHT MARK' (U+200E)
Here is a HTML version of the above with numeric character references to LRM, to visualize where the LRM is inserted:
فاکس: ‎+44 1908 215040
B. This text does render correctly in WPF:
فاکس: ‎+‎44‎ ‎1908‎ ‎210210
But it contains (I believe) unncessary LRM characters. I put together the text in a trial-and-error fashion.
Here is the HTML version with the extra LRM characters
فاکس: ‎+‎44‎ ‎1908‎ ‎215040‎
Why are the extra characters needed / what am I doing wrong with the original text?
Note: The problem occurs IFF setting the Language property, either explicitly in XAML or code (like Language="fa-IR") or by overriding the default value of the Language property in code (assuming current culture being "fa-IR") as so:
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
If I leave the language property as en-US, the text renders correctly in WPF, but I really need to set the Language to have value conversions work without having to set the ConverterCulture explicitly on each and every data binding that could be binding to some culture dependent data.
There are also other problems, like LRO ('LEFT-TO-RIGHT OVERRIDE' (U+202D)) being ignored.
I really need help understanding what is going on, as this could turn out to be a show stopper for localizing my application to Persian and Arabic.
I suspect that I am the one doing something wrong, as I fail to google for the problem.
Here is a a related post on MS Connect, but no one has so far confirmed the behaviour as a bug:
http://connect.microsoft.com/WPF/feedback/details/682784/incorrect-unicode-bidi-behaviour#
Note: I am not that familiar with the BiDi algorithm in general and know even less of the actual implementation in WPF. I have a basic understanding of Unicode.

XAML to HTML converter

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.

How to create a shape acting like a textbox?

Please refer this control
http://www.charlespetzold.com/blog/2009/10/Using-Text-Outlines-in-Silverlight.html
The formattedtext control is a shape which helps to generate the shape of the text with proper geometry. I would like to make this control act like a text box with cursors and features like typing in from keyboard.
Right now I use an invisible text box with a formattedtext control to act like that. But the cursor position always creates a problem when the size of the text is not equal to the size of the rendered text as shape.
Can anyone please show the way to achieve this.
Well, I built a syntax highlighting textbox using the method you describes.
Actually, at first I wanted to rebuilt everything too, but I thought : I have to build the caret fonctionnalities, the selection brush, manage a lot of different events, like selection with mouse or keyboard, deletion, Copy/Cut/Paste, etc etc...
That's a LOT of work, and windows users are used to select text in textboxes for instance, so this complex implementation cannot be left unimplemented. We must follow some Microsoft guidance on how a textbox must feel.
Actually, I think that building a new textbox from scratch is not the way to go. I suggest you to continue on your current method. If you have different fonts in the same textbox, use a RichTextBox, and handle the font changes in the textbox as well as in the formatted text.
Also, a good think to implement is to only draw the visible text with the formattedtext (but only if the user can write several hundreds of text lines).

Resources