Question

I'm doing this WPF tutorial and for some reason I get an error when adding a custom SlidersToColorConverter class to resources.

Someone on StackOverflow was doing it exact same way.

MainWindow.xaml:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication2"
    Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <local:SlidersToColorConverter x:Key="whyareyounotworking"/>
    </Window.Resources>
</Window>

SlidersToColorConverter.cs:

namespace WpfApplication2
{
    class SlidersToColorConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double red = (double)values[0];
            double green = (double)values[1];
            double blue = (double)values[2];
            return new SolidColorBrush(Color.FromArgb(255, (byte)red, (byte)green, (byte)blue));
        }

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

Error List:

The name "SlidersToColorConverter" does not exist in the namespace "clr-namespace:WpfApplication2". c:\users\mateusz\documents\visual studio 2013\Projects\WpfApplication2\WpfApplication2\MainWindow.xaml  39  9   WpfApplication2
Was it helpful?

Solution

It looks like the class is private (by default). You must change your definition to

public class SlidersToColorConverter : IMultiValueConverter
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top