【问题标题】:a class that is in my namespace is getting an error that it is not in my namespace我的命名空间中的一个类收到一个错误,它不在我的命名空间中
【发布时间】:2017-08-31 19:48:04
【问题描述】:

我有两个几乎相同的转换器,其中一个在我的 XAML 中出现错误,它显然不存在于命名空间中。 我尝试清理和重建项目。打开和关闭视觉工作室。重新启动。删除并重新创建有问题的类。手动重新键入类而不是复制和粘贴它。验证我的 XAML 没有错误。验证该类没有错误。我仍然收到它不在命名空间中的错误。任何帮助都会很棒

我的代码:

namespace ScoreBoardClientTest
{
    class LunchRangeToBooleanConverterTime : IValueConverter
    {
        private static readonly TimeSpan _toCompare = new TimeSpan(00, 60, 00);

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is TimeSpan))
                return DependencyProperty.UnsetValue;
            return (TimeSpan)value > _toCompare;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("To Long On Lunch");
        }      
    }
}

我的 XAML 存在错误。错误在于午餐范围到布尔转换器时间

<DataGrid.Resources>
 <local:BreakRangeToBooleanConverterTime x:Key="breakconvtime"/>                
 <local:LunchRangeToBooleanConverterTime x:Key="lunchconvtime"/>
</DataGrid.Resources>

我被要求分享的几乎相同的头等舱。这个我完全没有问题:

namespace ScoreBoardClientTest
{
    class BreakRangeToBooleanConverterTime : IValueConverter
    {
        private static readonly TimeSpan _toCompare = new TimeSpan(00, 15, 00);
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is TimeSpan))
                return DependencyProperty.UnsetValue;
            return (TimeSpan)value > _toCompare;
        }      

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("To Long On Break");
        }       
    }
}

【问题讨论】:

    标签: c# wpf xaml namespaces


    【解决方案1】:

    您是否在 XAML 页面顶部添加了 local 命名空间?我说的是

    xmlns:local="clr-namespace:ScoreBoardClientTest;assembly={CheckYourScoreBoardClientTestAssembly (Can be found on your Project Properties)}
    

    将此作为属性添加到您的页面/窗口标签中,以便使用您的类。

    【讨论】:

    • 这让我很困惑,因为第一堂课休息很好。我已经在 XAML 的顶部有 xmlns:local="clr-namespace:ScoreBoardClientTest" 但我没有程序集。我以前从未添加过程序集引用。我的意思是我会试试看,我只是不明白为什么。
    • 所以我正在查看我的程序集,所有我看到的是否是程序集:ComVisible(false) 和程序集 GUID
    • 可以也分享一下第一堂课吗?谢谢!
    • 添加了工人阶级。让我知道这是否有帮助。
    • 不确定这是否能解决问题,但您可以尝试将两个类的访问修饰符更改为public吗?
    猜你喜欢
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多