【问题标题】:Noobie WPF namespace and converter problemNoobie WPF 命名空间和转换器问题
【发布时间】:2011-01-09 21:51:05
【问题描述】:

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

无论如何,我一直在看这篇文章WPF: How to bind RadioButtons to an enum?,但我就是无法让转换器在 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>
...

任何帮助将不胜感激。

【问题讨论】:

    标签: .net wpf xaml namespaces converter


    【解决方案1】:

    在多次挠头(以及对着屏幕大喊大叫)之后,我发现了问题。

    原来标识命名空间不应该有程序集。

    我是这样定义的

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

    ...不过应该是这样的

    xmlns:local="clr-namespace:Widget"
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我认为这可能已经解决了问题,但是当我进行重建时,我仍然收到错误。
      猜你喜欢
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 2016-04-27
      相关资源
      最近更新 更多