Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Can't instantiate class in Window.Resources

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
like image 599
matt-pielat Avatar asked Apr 27 '14 11:04

matt-pielat


1 Answers

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

public class SlidersToColorConverter : IMultiValueConverter
like image 122
Jason Down Avatar answered Sep 21 '22 20:09

Jason Down