views:

21

answers:

2

The following xaml causes the text "Activate a test to the left." to be visible at run-time and at design-time (in Vs2010):

<TextBlock TextWrapping="Wrap">
    <TextBlock.Text>Activate a test to the left.</TextBlock.Text>
</TextBlock>

The following shows nothing at run-time, but the text IS visible at design-time:

<TextBlock TextWrapping="Wrap">
    <TextBlock.Text><![CDATA[Activate a test to the left.]]></TextBlock.Text>
</TextBlock>

What's the problem?

+1  A: 

The designer view can often be different from what you actually see at runtime. The designer does not run all the code just some of it, it makes some heuristic assumptions and its based on WPF not Silverlight.

So especially for Silveright apps what you see is not necessarily what you get.

Evidentently the Silverlight Xaml parser doesn't take to kindly to the CDATA section. Why would you do that anyway?

AnthonyWJones
I just wanted to put a bunch of text on the page and without CDATA, I can't use special characters.
wizlb
+1  A: 

Here is an extensive discussion on this very topic:

http://forums.silverlight.net/forums/t/187623.aspx

enforge
That thread was funny. The basic conclusion is that it can't be done. I really don't put literal text right into my xaml anyway, but I was surprised that it didn't work the way it worked in the designer. The obvious solution is basically to load the text in your code-behind or view-model class and bind to it in xaml.
wizlb