当使用Silverlight Toolkit控件时,我在Expression Blend中打开我的UserControl遇到了一个奇怪的问题。 我的UserControl使用Toolkit的ListBoxDragDropTarget,如下所示:
<controlsToolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox ItemsSource="{Binding MyItemControls}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</controlsToolkit:ListBoxDragDropTarget>
在运行时一切都按预期工作,并且在Visual Studio 2008中看起来很好。然而,当我尝试在Blend中打开我的UserControl时,我得到了一个XamlParseException:[行:0 位置:0],我无法在设计视图中看到任何内容。更具体地说,Blend抱怨道:
“元素“ListBoxDragDropTarget”无法显示,因为存在System.Windows.Controls.ListBoxDragDropTarget的问题:TargetType不匹配。”
我的silverlight应用程序正在引用来自2009年11月工具包发布的System.Windows.Controls.Toolkit,我已确保包括这些ListoxDragDropTarget的命名空间声明:
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit"
如果我注释掉ListBoxDragDropTarget控件包装器,只留下ListBox,我可以在设计视图中看到一切都很好,没有错误。此外,我意识到这种情况发生在各种Silverlight Toolkit控件上,因为如果我注释掉ListBoxDragDropTarget并用其他控件替换它,则也会出现同样的问题。
<controlsToolkit:BusyIndicator />
在Blend中发生了完全相同的错误。更奇怪的是,如果我在Blend中启动一个全新的Silverlight应用程序,我可以添加这些工具包元素而不会出现任何错误,因此似乎是发生在我的项目引用工具包程序集时的一些愚蠢问题。
我非常确定这与从其generic.xaml加载工具包控件的默认样式有关,因为错误与TargetType有关,而Blend可能正在尝试加载默认样式。
是否有人遇到过这个问题或者对我的问题有任何想法?