8

使用 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 可能正在尝试加载默认样式有关。

有没有人遇到过这个问题,或者对我的问题有什么想法?

4

4 回答 4

11

嗨,我们遇到了完全相同的问题,我们通过检查项目中存在此问题的引用来解决它。所有引用的工具包程序集都应位于磁盘上的同一目录中。

我们对 System.Windows.Controls.Toolkit.dll 的项目引用总是“跳”回导致我们问题的原始路径。我们通过在记事本++(或任何您喜欢的文本编辑器)中编辑项目文件并硬编码它可以找到程序集的路径来解决。

希望这可以帮助。

于 2010-08-17T13:43:31.353 回答
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”

于 2010-07-13T06:02:36.517 回答
1

我正在使用 Silverlight 5 工具包,并且在 Expression Blend for SL 5 中XamlParseException使用BusyIndicator工具包控件时,上述所有解决方案都没有帮助,但我找到了另一种解决方法,它相当脏,但允许我BusyIndecator在 Expression Blend 中工作,

  1. 源于控制

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

于 2012-04-09T11:46:52.487 回答
0

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

我知道它有点 C++y,但我可以想象这是因为我们在模板内间接引用了包装面板,而不是在顶层页面上,所以加载器不知道在初始化时要加载什么。不过,我真的很想了解确切的原因。

我只是System.Windows.Controls.Toolkit在后面的代码中引用并介绍了以下成员:

System.Windows.Controls.WrapPanel _dummy;
于 2012-12-01T18:24:54.913 回答