Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight 4: "Invalid XAML" using Converter in DataTemplate

maybe you could help me understand why I get an unhandled exception "Invalid XAML" in Visual Studio 2010 designer when trying to do the following on a Page.

I have a Converter named DateTimeConverter that converts a date into a German date string. The converter works fine. I've included the namespace and added the following to the page's resources:

<navigation:Page.Resources>
    <myClasses:DateTimeConverter x:Key="dateTime" />
</navigation:Page.Resources>

Now I have a list box that I want to bind to a list of objects. I do the binding in code, but I would like to define the data template. Thus I've added the following to my layout:

<ListBox x:Name="lbConversation" BorderBrush="#00000000">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="0" Padding="4">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{Binding Message, Mode=OneWay}" />
                    <TextBlock Text="{Binding TimeStamp, Mode=OneWay, Converter={StaticResource dateTime}}" />
                </StackPanel>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And this works fine when I run. However, in the code section, the code for the data template is undercurled and the designer says "Invalid XAML". When I remove the Converter=... part, this error is gone.

Is this a designer bug? What can I do?

EDIT
By the way: The exact same code does not throw the error within a WPF project!

like image 432
Thorsten Dittmar Avatar asked Sep 21 '10 10:09

Thorsten Dittmar


2 Answers

Just adding to this question as I found a solution.

The solution to my case was here: http://forums.silverlight.net/post/618518.aspx

Apparently you must not have a space character in your project name or assembly name. D'oh!

Hope it helps.

like image 62
jingtao Avatar answered Oct 06 '22 21:10

jingtao


Sorry, can't replicate this at all, do you have some design-time data that may be the cause of the weird error?

Also, since you said that you're using the converter to output german dates... wouldn't it be easier to let the framework do this kind of things, as it probably does them a lot better? Set the entire application thread's CultureInfo to german and all formatting will be done with that culture's settings; of course it's still possible you only want some controls internationalized...

like image 36
Alex Paven Avatar answered Oct 06 '22 23:10

Alex Paven