WPF: Can't instantiate class in Window.Resources

﹥>﹥吖頭↗ 提交于 2019-12-22 08:36:28

问题


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

回答1:


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

public class SlidersToColorConverter : IMultiValueConverter


来源:https://stackoverflow.com/questions/23322591/wpf-cant-instantiate-class-in-window-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!