I am having some problems trying to add a ValueConverter in my xaml usercontrol:
at start I had problems just to add the reference to the local namespace, after some compiling/cleaning/recompiling it seems to finally see itself. Still, it says that my ValueConverter class cannot be found, to check that the assembly is referenced blah blah blah..
This is my XAML:
<UserControl x:Class="MySolution.GUI.StatusPanel"
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:local="using:MySolution.GUI"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MySolution.Styles;component/Styles.xaml" />
<ResourceDictionary Source="pack://application:,,,/MySolution.Styles;component/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Style ...>
<Setter Property="Background" Value="{Binding Path=DataContext.Column2, Converter={local:RowValueConverter}}" />
</Style>
</UserControl.Resources>
...
</UserControl>
And this is the converter:
namespace MySolution.GUI
{
public class RowValueConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Color.FromRgb(255, 255, 255);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}
Now, what I don’t understand is why it keeps on saying that
the tag ‘RowValueConverter’ does not exist in XML namespace ‘clr-namespace:MySolution.GUI’
How can I fix this?
Thanks
Edit: current status of XAML file
...
xmlns:local="using:MySolution.GUI"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="800">
<UserControl.Resources>
<local:RowValueConverter x:Key="rowValueConverter" />
<ResourceDictionary>
...
...
<Setter Property="Background" Value="{Binding Path=DataContext.Column2, Converter={StaticResource rowValueConverter}}" />
...
EDIT updated answer based on comment
Add following
after
Change following
To
You have not defined the resource anywhere, and trying to use class name instead of resource in existing code
Old answer
Change
to
or