我需要一些语法帮助来在XAML中为单独的类中的方法定义资源。第<c:StatusToColour x:Key="MyConverter"/>
行给出了以下错误
The name "StatusToColour" does not exist in the namespace "clr-namespace:ProjectXYZ".
所以看起来它没有在XAML中识别xmlns:c="clr-namespace:ProjectXYZ"
。请问有人可以提供正确的语法建议吗?
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>
答案 0 :(得分:0)
尝试使用带有显式程序集名称的完整语法,例如:
xmlns:mvvm="clr-namespace:ProjectXYZ;assembly=ProjectXYZ"