Silverlight 4:“无效的XAML”在DataTemplate中使用Converter [英] Silverlight 4: "Invalid XAML" using Converter in DataTemplate
问题描述
也许您可以帮助我理解为什么在 Page
上尝试执行以下操作时,为什么在Visual Studio 2010设计器中出现未处理的异常无效XAML。
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
.
我有一个名为 DateTimeConverter
的 Converter
,它将一个日期转换为一个德国日期字符串。转换器工作正常。我已经包含了名称空间,并在页面资源中添加了以下内容:
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>
这在我跑步时工作正常。但是,在代码部分中,数据模板的代码未充分了解,设计人员说 Invalid XAML。当我删除 Converter = ...
部分时,此错误消失了。
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?
编辑
顺便说一句:完全相同的代码不会在WPF项目!
EDIT
By the way: The exact same code does not throw the error within a WPF project!
推荐答案
在我找到解决方案后,只需添加此问题即可。
Just adding to this question as I found a solution.
这里的解决方案是: http://forums.silverlight.net/post/618518.aspx
显然,您的项目名称或程序集名称中不得包含空格。
Apparently you must not have a space character in your project name or assembly name. D'oh!
希望它会有所帮助。
这篇关于Silverlight 4:“无效的XAML”在DataTemplate中使用Converter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!