【问题标题】:XAML can't see a classXAML 看不到类
【发布时间】:2014-09-07 03:47:11
【问题描述】:

我的 xaml 是这样的:

<DataGrid.Resources>
    <Helpers:EnumHelper x:Key="EnumHelper" />
</DataGrid.Resources>

我的班级是这样定义的:

namespace MyProj.View.UserControlHelpers {
    public class EnumHelper { }
}

我得到的错误是这样的:

命名空间“clr-namespace:MyProj.View.UserControlHelpers”中不存在名称“EnumHelper”。

我已经从工作室清理了这个项目,然后我删除了 bin 和 obj 子目录中的每个文件,我什至更改了类名,但仍然没有成功 - 我仍然收到此错误。

编辑:

我的 xaml 标头是这样的:

<UserControl x:Class="MyProj.View.Partials.TableWindow.Columns"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:cmd="http://www.galasoft.ch/mvvmlight"
             xmlns:Helpers="clr-namespace:MyProj.View.UserControlHelpers"
             xmlns:Model="clr-namespace:MyProj.Model"
             xmlns:ModelHelpers="clr-namespace:MyProj.Model.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

【问题讨论】:

  • 我不明白。你想让我做什么?
  • 显示您的 XAML 标头,其中包含描述 XML 命名空间和导入的 CLR 命名空间的所有属性。
  • @Athari - 我编辑了我的问题
  • 您何时收到错误消息?如果您在编辑器中创作 XAML 时得到它,而不是编译您的项目,请尝试(重新)构建。

标签: c# wpf xaml


【解决方案1】:

你的类命名空间是

MadMin.View.UserControlHelpers

但您在 xaml 中将其称为

MyProj.View.UserControlHelpers

【讨论】:

  • 如果命名空间名称一直相同,如问题的更新版本所述,这如何解决问题?
  • 实际上命名空间名称是不一样的——在一台计算机上(这段代码工作的地方)——它们是相同的,而在另一台机器上(这不工作的地方)它们不是。
猜你喜欢
  • 2018-06-10
  • 2022-10-25
  • 2019-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-14
  • 2012-06-29
  • 1970-01-01
相关资源
最近更新 更多