在Expression Blend中使用Silverlight Toolkit控件时出现XamlParseException

8

当使用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可能正在尝试加载默认样式。
是否有人遇到过这个问题或者对我的问题有任何想法?

表达式混合 3,具体是 3.0.1927.0 版本。 - Dan Auclair
4个回答

11

你好,我们曾经遇到和你一样的问题,我们通过检查项目中引用的内容来解决它。所以所有被引用的工具包程序集都应该在磁盘上相同的目录下。

我们发现,我们的项目引用到 System.Windows.Controls.Toolkit.dll 的路径总是“跳回”原始路径,这就导致了我们的问题。我们通过在 Notepad++(或任何你喜欢的文本编辑器)中编辑项目文件,并将可以找到程序集的路径硬编码,最终解决了这个问题。

希望这有所帮助。


我很久以前就放弃了这个有问题的项目,转而做其他事情,所以我无法验证它。现在我将把它标记为答案,因为看起来其他人也面临着这个问题,如果它不能解决大多数人的问题,我可以重新打开它。 - Dan Auclair

5

对于Visual Studio(可能包括Blend),您需要添加对以下内容的引用:

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)在“C:\ Program Files(x86)\ Microsoft SDKs \ Silverlight \ v5.0 \ Toolkit \ dec11 \ Bin \ System.Windows.Controls.Toolkit.Internals.dll”中。 - andrewpm

1

我正在使用Silverlight 5工具包,在Expression Blend for SL 5中使用BusyIndicator工具包控件时遇到了XamlParseException,所有以上的解决方案都没有帮助,但我找到了另一个解决方法,它相当不好,但允许我在Expression Blend中使BusyIndecator正常工作。

  1. 从控件派生

    public class BusyIndicatorEx : BusyIndicator
    {
        public BusyIndicatorEx()
        {
            this.DefaultStyleKey = typeof(BusyIndicatorEx);
        } 
    }
    
  2. 为派生控件创建样式(只需将BusyIndicator源代码中的样式复制到themes/generic.xaml,并将目标类型更改为local:BusyIndicatorEx


我该如何复制BusyIndicator的样式?“themes/generic.xaml”在哪里? - Jordan

0

我曾经遇到过同样的问题,通过在代码后台引入一个虚拟引用到Wrap Panel来解决了这个问题。

我知道这有点像C++,但我可以想象这是因为我们在模板内部有对Wrap Panel的间接引用,而不是在顶层页面上,所以加载程序不知道在初始化时要加载什么。虽然我真的很想了解确切的原因。

我只是引用了System.Windows.Controls.Toolkit并在代码后台引入了以下成员:

System.Windows.Controls.WrapPanel _dummy;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接