XAML 设计器“找不到类型”当转换器位于 UserControl.Resources 中时

发布于 2024-08-22 10:12:16 字数 1150 浏览 4 评论 0原文

我有一个 WPF UserControl,其引用的绑定转换器如下:

<UserControl x:Class="MyControl" x:Name="MyControl"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="clr-namespace:TheMainNamespaceOfThisAssembly">

    <UserControl.Resources>
      <local:ConfidenceColorConverter x:Key="ConfidenceColorConverter"/>
    </UserControl.Resources>

然后我稍后使用绑定转换器。我在设计窗口中看到用户控件。然后我进行编译,然后将此用户控件放置在我的主窗口中。我运行它并且它有效。但是,我仍然想在主窗口上使用设计器,它会中断:

无法创建“MyControl”类型的实例。

所以我学习了如何调试设计器;当我这样做时,我得到一个 XamlParseException:

找不到类型“TheMainNamespaceOfThisAssembly.ConfidenceColorConverter”。编译时使用的程序集可能与加载时使用的程序集不同,并且类型丢失。标记文件错误...

如果删除对转换器的引用,我的用户控件将在主窗口的设计器中正常显示。 有什么想法可以修复我对转换器的引用,以便它们不会破坏设计器吗?

无法理解文章WPF 设计器加载失败疑难解答是否适用。

I have a WPF UserControl with binding converters referenced like this:

<UserControl x:Class="MyControl" x:Name="MyControl"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="clr-namespace:TheMainNamespaceOfThisAssembly">

    <UserControl.Resources>
      <local:ConfidenceColorConverter x:Key="ConfidenceColorConverter"/>
    </UserControl.Resources>

I then use the binding converter later. I see the user control in my design window. Then I compile, then place this user control in my main window. I run it and it works. However, I still would like to use the designer on the main window, which breaks with:

Could not create an instance of type 'MyControl'.

So I learned how to debug the designer; when I do, I get an XamlParseException:

Cannot find type 'TheMainNamespaceOfThisAssembly.ConfidenceColorConverter'. The assembly used when compiling might be different than that used when loading and the type is missing. Error in markup file...

If remove the references to the converters, my user control displays well in the designer on the main window. Any ideas how to fix my references to the converters so that they won't break the designer?

Couldn't understand if the article Troubleshooting WPF Designer Load Failures applies or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

囍笑 2024-08-29 10:12:16

您能否尝试在一个干净的新项目上重现该问题,而不是编辑现有项目?您不能这样做

<UserControl x:Class="MyControl" x:Name="MyControl"...

,因为您需要将命名空间添加到“x:class”并将“x:Name”值更改为与类名不同。当我按照您的描述创建一个干净的项目并修复此类错误时,设计器工作正常。您可能会忽略问题中的一些您认为不重要的细节,但这些细节可能会产生重大影响。

Could you please try to reproduce the problem on a clean new project rather than editing your existing one? You cannot have

<UserControl x:Class="MyControl" x:Name="MyControl"...

as you would need to add a namespace to "x:class" and change "x:Name" value to be different from class name. The designer works fine when I create a clean project as you describe and fix this sort of errors. You might be omitting some details from the question you think are unimportant, but those details can make all the difference.

浅唱々樱花落 2024-08-29 10:12:16

与其他人交谈后,VS2008设计器存在许多问题,导致其在许多情况下无法使用。我们放弃了。

更新:似乎有些人,尤其是 Joel Cochran,正在使用 Expression Blend 设计视图取得更大的成功,只要您遵守他的 XAML开发中MVVM的四个原则

After talking with others, the VS2008 designer has numerous problems that prevent its use in many situations. We gave up.

Update: It seems like some, especially Joel Cochran, are using the Expression Blend design view with more success, as long as you obey his four principles of MVVM in XAML development.

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