Я пытаюсь использовать конвертер значений.Однако VS жалуется на этот XAML:
<Grid x:Name="LayoutRoot" Background="White" Height="Auto" Width="Auto">
<Grid.Resources>
<local:DateFormatter x:Key="FormatConverter" />
</Grid.Resources>
Ошибка:
The type 'local:DateFormatter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Я пропустил ссылку на сборку или мой XAML неверен?Я пытаюсь следовать примеру на MSDN .
Обновление : я добавил следующий атрибут в UserControl
:
xmlns:local="clr-namespace:MyNamespace"
Я также добавил класс DateFormatter.
Теперь Intellisense появляется с «local» и «DateFormatter».Тем не менее, он по-прежнему выдает ту же ошибку, что и выше.Ошибка не возникает для других типов, таких как App
.
DateFormatter:
using System;
...
namespace MyNamespace
{
public class DateFormatter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DateTime date = (DateTime) value;
return date.ToShortDateString();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}