我需要一些语法帮助,以便在 XAML 中为单独的类中的方法定义资源。该行<c:StatusToColour x:Key="MyConverter"/>
给了我以下错误
The name "StatusToColour" does not exist in the namespace "clr-namespace:ProjectXYZ".
所以看起来它xmlns:c="clr-namespace:ProjectXYZ"
在 XAML 中无法识别。请问有人可以就正确的语法提出建议吗?
StatusToColour.cs:(在项目根文件夹中)
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace ProjectXYZ
{
public class StatusToColour : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//more code
}
}
}
MainControl.xaml:
<UserControl x:Class="ProjectXYZ.Content.MainControl"
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:c="clr-namespace:ProjectXYZ"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="400">
<UserControl.Resources>
<c:StatusToColour x:Key="MyConverter"/>
</UserControl.Resources>
</UserControl>