Noobie WPF命名空间和转换器问题(Noobie WPF namespace and converter problem)

编程入门 行业动态 更新时间:2024-10-21 09:27:24
Noobie WPF命名空间和转换器问题(Noobie WPF namespace and converter problem)

请原谅noob问题,但我会围成一圈并需要答案......

无论如何,我一直在看这篇文章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://schemas.microsoft.com/winfx/2006/xaml/presentation ”中不存在标记“EnumBooleanConverter”。

我已经尝试添加对程序集的引用,然后将标记附加到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.

最满意答案

经过多次头部刮擦(并在屏幕上大量喊叫),我发现了问题所在。

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

我这样定义它

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"

更多推荐

本文发布于:2023-07-14 20:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107263.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换器   空间   WPF   Noobie   converter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!