在 Expression Blend 中使用 Silverlight Toolkit 控件的 XamlParseException
使用 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]< /strong> 我在设计视图中看不到任何内容。更具体地说,Blend 抱怨道:
由于 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 可能正在尝试加载默认样式。
有人以前遇到过这个问题或者对我的问题有什么想法吗?
I am having a strange issue opening up my UserControl in Expression Blend when using a Silverlight Toolkit control. My UserControl uses the toolkit's ListBoxDragDropTarget as follows:
<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>
Everything works as expected at runtime and looks fine in Visual Studio 2008. However, when I try to open my UserControl in Blend I get XamlParseException: [Line: 0 Position: 0] and I can not see anything in the design view. More specifically Blend complains:
The element "ListBoxDragDropTarget" could not be displayed because of a problem with System.Windows.Controls.ListBoxDragDropTarget: TargetType mismatch.
My silverlight application is referencing System.Windows.Controls.Toolkit from the Nov. 2009 toolkit release, and I've made sure to include these namespace declarations for the ListBoxDragDropTarget:
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit"
If I comment out the ListBoxDragDropTarget control wrapper and just leave the ListBox I can see everything fine in the design view without errors. Furthermore, I realized this is happening with a variety of Silverlight Toolkit controls because if I comment out ListBoxDragDropTarget and replace it with
<controlsToolkit:BusyIndicator />
the same exact error occurs in Blend. What is even weirder is that if I start a brand new silverlight application in blend I can add these toolkit elements without any kind of error, so it seems like something dumb that is happening with my project references to the toolkit assemblies.
I'm pretty sure this has something to do with loading the default styles for the toolkit controls from its generic.xaml, since the error has to do with the TargetType and Blend is probably trying to load up the default styles.
Has anyone encountered this issue before or have any ideas as to what may be my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您好,我们遇到了完全相同的问题,我们通过检查存在此问题的项目中的参考文献来解决它。所有引用的工具包程序集应位于磁盘上的同一目录中。
我们的项目对 System.Windows.Controls.Toolkit.dll 的引用总是“跳”回导致问题的原始路径。我们通过在记事本++(或任何您喜欢的文本编辑器)中编辑项目文件并硬编码可以找到程序集的路径来解决。
希望这有帮助。
Hi we had exactly the same issue, we solved it by checking the references in the project which was having this problem. All referenced toolkit assemblies should be in the same directory on disk.
Our project reference to the System.Windows.Controls.Toolkit.dll always 'jumped' back to the orginal path which was causing our issue. We solved by editing the project file in notepad++ (or any of your favorite text-editor) and hardcode the path where it could find the assembly.
Hope this helps.
对于 Visual Studio(也可能是 Blend),您需要添加对:
System.Windows.Controls.Toolkit.Internals.dll
“C:\Program Files\Microsoft SDKs\Silverlight\v4.0\工具包\Apr10\Bin\System.Windows.Controls.Toolkit.Internals.dll”
For Visual Studio (maybe Blend too) you need to add a reference to :
System.Windows.Controls.Toolkit.Internals.dll
"C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin\System.Windows.Controls.Toolkit.Internals.dll"
我正在使用 Silverlight 5 工具包,并且在 SL 5 的 Expression Blend 中使用
BusyIndicator
工具包控件时出现XamlParseException
,所有上述解决方案都没有帮助,但我找到了另一种解决方法,其相当脏,但允许我使BusyIndecator
在 Expression Blend 中工作,从控制中派生
为派生控件创建样式(只需将样式从
BusyIndicator
源代码复制到themes/generic.xaml,并将目标类型更改为local :BusyIndicatorEx
)I'm using Silverlight 5 toolkit and having
XamlParseException
when usingBusyIndicator
toolkit control in Expression Blend for SL 5, all above solutions didn't helped but I found another workaround, its rather dirty but allows me to makeBusyIndecator
work in Expression Blend,derive from control
create style for derived control (just copy style from
BusyIndicator
source code to themes/generic.xaml, and change target type tolocal:BusyIndicatorEx
)我遇到了同样的问题,通过在包裹面板后面的代码中引入虚拟引用已经解决了这个问题。
我知道它有点 C++y,但我可以想象这是因为我们在模板内间接引用了包装面板,而不是在顶级页面上,因此加载器不知道在初始化时加载什么。不过,我真的很喜欢了解确切的原因。
我刚刚引用了 System.Windows.Controls.Toolkit 并在后面的代码中引入了以下成员:
I had the same problem which has been resolved by introducing a dummy reference in code behind to the Wrap Panel.
I know it is a little C++y but I can imagine it is because we have indirect reference to wrap panel inside a template and not on the top level page so the loader don't know what to load on initialization. I really like understand the exact reason, though.
I just referenced
System.Windows.Controls.Toolkit
and introduce following member in code behind: