Noobie WPF 命名空间和转换器问题

发布于 2024-08-19 07:16:59 字数 1556 浏览 3 评论 0原文

请原谅菜鸟问题,但我在兜圈子,需要答案......

无论如何,我一直在看这篇文章WPF:如何将 RadioButtons 绑定到枚举? 但我无法在 XAML 文件中识别转换器。

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

我有一个单独的文件保存 EnumBooleanConverter 类,但上面的引用给了我以下错误:

错误 1 ​​XML 命名空间“http:/ 中不存在标记“EnumBooleanConverter” /schemas.microsoft.com/winfx/2006/xaml/presentation'。

我尝试添加对程序集的引用,然后将标记附加到 XAML,但无济于事。

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:local="clr-namespace:Widget;assembly=Widget"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <local:EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

任何帮助将不胜感激。

Please forgive the noob question but I'm going round in circles and need answers...

Anyway, I've been looking at this article WPF: How to bind RadioButtons to an enum? but I just can't get the convertor to be recognised within the XAML file.

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

I have a seperate file holding the EnumBooleanConverter class but the above reference gives me the following error:

Error 1 The tag 'EnumBooleanConverter' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

I've tried adding references to the assembly and then appending the tag to the XAML but to no avail.

<Window x:Class="Widget.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:local="clr-namespace:Widget;assembly=Widget"
    Title="Widget" Height="366" Width="588" WindowStyle="SingleBorderWindow">
    <Window.Resources>
        <local:EnumBooleanConverter x:Key="enumBooleanConverter" />
    </Window.Resources>
...

Any help would be greatly appreciated.

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

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

发布评论

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

评论(2

起风了 2024-08-26 07:16:59

经过多次绞尽脑汁(以及对着屏幕大喊大叫)后,我发现了问题所在。

事实证明,识别命名空间不应该有程序集。

我是这样定义的

xmlns:local="clr-namespace:Widget;assembly=Widget"

......但它应该是这样的

xmlns:local="clr-namespace:Widget"

After much head scratching (and a fair amount of shouting at the screen) I have identified the problem.

It turns out that identifying the namespace shouldn't have the assembly.

I was defining it like this

xmlns:local="clr-namespace:Widget;assembly=Widget"

... But it should have just been like this

xmlns:local="clr-namespace:Widget"
怪我太投入 2024-08-26 07:16:59

确保 EnumBooleanConverter 是可公开访问的,并且它有一个公共的空构造函数。

Make sure EnumBooleanConverter is publicly accessible and it has a public empty constructor.

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