gpt4 book ai didi

c# - XAML 为转换器类添加命名空间

转载 作者:太空狗 更新时间:2023-10-30 00:53:31 26 4
gpt4 key购买 nike

我一直收到“名称 xxx 在 yyy 中不存在”。我不明白为什么,我想我尝试了所有可能的组合。

我所有的 cs 文件,包括主窗口都在“Web_Media_Seeker_WPF”命名空间中

Converters.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Web_Media_Seeker_WPF.WPFConverters
{
public class BoolToValueConverter<T> : IValueConverter
{
public T FalseValue { get; set; }
public T TrueValue { get; set; }

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return FalseValue;
else
return (bool)value ? TrueValue : FalseValue;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value != null ? value.Equals(TrueValue) : false;
}
}

public class BoolToObjectConverter : BoolToValueConverter<Object> { }
public class BoolToStringConverter : BoolToValueConverter<String> { }
public class BoolToBrushConverter : BoolToValueConverter<System.Windows.Media.Brush> { }
public class BoolToVisibilityConverter : BoolToValueConverter<System.Windows.Visibility> { }
public class BoolToColorConverter : BoolToValueConverter<System.Windows.Media.Color> { }
public class BoolToImageSourceConverter : BoolToValueConverter<System.Windows.Media.ImageSource> { }
public class BootToBoolConverter : BoolToValueConverter<bool> { }

public class AddValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
object result = value;
int Value;

if (value != null && targetType == typeof(Int32) &&
int.TryParse((string)parameter,
System.Globalization.NumberStyles.Integer, culture, out Value))
{
result = (int)value + (int)Value;
}

return result;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

MainWindow.xaml

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namesapce:Web_Media_Seeker_WPF.WPFConverters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Web_Media_Seeker_WPF.MainWindow"
Title="Web Media Seeker"
Height="563"
Width="836">
<Window.Resources>
<local:BoolToImageSourceConverter x:Key="BoolToWorkImageSource"
TrueValue="Images/work.png"
FalseValue="Images/idle.png" />
<local:BootToBoolConverter x:Key="InvertBool"
TrueValue="False"
FalseValue="True" />
<local:BoolToStringConverter x:Key="WorkTooltip"
TrueValue="Working..."
FalseValue="Idle" />
</Window.Resources>
and stuff...

我有错误:

The name "BoolToImageSourceConverter" does not exist in the namespace "clr-namesapce:Web_Media_Seeker_WPF.WPFValuesConverters".

The name "BoolToStringConverter" does not exist in the namespace "clr-namesapce:Web_Media_Seeker_WPF.WPFValuesConverters".

The name "BootToBoolConverter" does not exist in the namespace "clr-namesapce:Web_Media_Seeker_WPF.WPFValuesConverters".

The tag 'BoolToImageSourceConverter' does not exist in XML namespace 'clr-namesapce:Web_Media_Seeker_WPF.WPFValuesConverters'.

The type 'local:BoolToImageSourceConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

The type 'local:BoolToStringConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

The type 'local:BootToBoolConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

最佳答案

您的命名空间声明中存在错误:

xmlns:local="clr-namesapce:Web_Media_Seeker_WPF.WPFConverters"

应该是

xmlns:local="clr-namespace:Web_Media_Seeker_WPF.WPFConverters"

你把 namesapce 而不是 namespace

关于c# - XAML 为转换器类添加命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16130479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com