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]
# 1

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”.

Yi-LunLuo-MSFT at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
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 ......... ?
logN at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

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 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
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.
Yi-LunLuo-MSFT at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5
So are you saying I should not use XamlWriter?
Tom at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6

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".

Yi-LunLuo-MSFT at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified