使用 Silverlight Toolkit 控件时,我在 Expression Blend 中打开 UserControl 时遇到一个奇怪的问题。我的 UserControl 使用工具包的 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: [Line: 0 Position: 0]并且我在设计视图中看不到任何东西。更具体地说,混合抱怨:
由于 System.Windows.Controls.ListBoxDragDropTarget 存在问题,无法显示元素“ListBoxDragDropTarget:TargetType 不匹配”。
我的 silverlight 应用程序引用了 2009 年 11 月发布的工具包中的 System.Windows.Controls.Toolkit,并且我确保为 ListBoxDragDropTarget 包含这些命名空间声明:
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 可能正在尝试加载默认样式有关。
有没有人遇到过这个问题,或者对我的问题有什么想法?