Bug in XamlReader?
It looks like XamlReader is buggy. In the following example, the text of a run goes from {}hello to {}{}hello after being written and read.
Is this a bug?
privatestaticvoid TestDocument(){
FlowDocument doc =newFlowDocument();Paragraph p =newParagraph();p.Inlines.Add(
newRun("{}hello"));doc.Blocks.Add(p);
string s =XamlWriter.Save(doc);s = s;
using (TextReader reader =newStringReader(s)){
using (XmlReader reader2 =newXmlTextReader(reader)){
doc = (
FlowDocument)XamlReader.Load(reader2);p = (
Paragraph)doc.Blocks.FirstBlock;Run r1 = p.Inlines.FirstInlineasRun;s = r1.Text;
Debug.Assert(s =="{}{}hello"); ///<!is this a bug?}
}
}
[2560 byte] By [
Tom] at [2008-1-6]
Hello, {} is an escaping sequence reserved by XAML. Without an extra {}, your Run will display “hello” on the screen, not “{}hello”. The XamlWriter thinks you what want to display is “{}hello”, so it adds an extra {}. So if you only want to display “hello”, you just need to write “hello”.
If u are using Expression blend to design forms some characters gets added to the content of any control; if u open that xaml in vs2005 u will not get same output ...........
Is this bug or ......... ?
Yi-Lun,
Thanks for your reply.
If I want to display "hello", I'll set the text to "hello".
Fair enough.
What about if I want to display "{}hello". How can I do this and use persistence?
Maybe I am missing something here but I have not found a reliable way to accomplish this.
Tom at 2007-9-28 >

To display "{}hello", you just write "{}hello" as the parameter of Run's constructor. But if you want to manually write the XAML file without XamlWriter, you'll need to write "{}{}hello" like the generated XAML.
If you're using XamlWriter, you should write "hello" to display "hello" and write "{}hello" to display "{}hello".
If you're typing XAML markup manually, you should write "hello" to display "hello" and write "{}{}hello" to display "{}hello".