在 Expression Blend 中使用 Silverlight Toolkit 控件的 XamlParseException

发布于 2024-08-18 04:51:24 字数 1858 浏览 7 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

圈圈圆圆圈圈 2024-08-25 04:51:24

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

我们的项目对 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.

不爱素颜 2024-08-25 04:51:24

对于 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"

哭了丶谁疼 2024-08-25 04:51:24

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

  1. 从控制中派生

    公共类 BusyIndi​​catorEx : BusyIndi​​cator
    {
        公共 BusyIndi​​catorEx()
        {
            this.DefaultStyleKey = typeof(BusyIndi​​catorEx);
        } 
    }
    
  2. 为派生控件创建样式(只需将样式从BusyIndi​​cator源代码复制到themes/generic.xaml,并将目标类型更改为local :BusyIndi​​catorEx)

I'm using Silverlight 5 toolkit and having XamlParseException when using BusyIndicator 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 make BusyIndecator work in Expression Blend,

  1. derive from control

    public class BusyIndicatorEx : BusyIndicator
    {
        public BusyIndicatorEx()
        {
            this.DefaultStyleKey = typeof(BusyIndicatorEx);
        } 
    }
    
  2. create style for derived control (just copy style from BusyIndicator source code to themes/generic.xaml, and change target type to local:BusyIndicatorEx)

千紇 2024-08-25 04:51:24

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

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

我刚刚引用了 System.Windows.Controls.Toolkit 并在后面的代码中引入了以下成员:

System.Windows.Controls.WrapPanel _dummy;

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:

System.Windows.Controls.WrapPanel _dummy;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文