0

I have read this SOF Post: How to properly reference a class from XAML But i cannot get this work. Because my converter class is subclass, i cannot get reference on XAML.

The Converter Class:

using System;
using System.Windows;
using System.Windows.Data;


namespace GapView.Classes
{
    public class ConverterClass
    {
        public class PhotoBorderConverter : IValueConverter
        {

            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                int width = System.Convert.ToInt32(value);
                return width + 16;
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                int width = System.Convert.ToInt32(value);
                return width - 16;
            }
        }
    }

}

And the MainWindow.xaml, XML section, i add

xmlns:GapView="clr-namespace:GapView"
xmlns:Classes="clr-namespace:GapView.Classes"

Inside

<Classes:ConverterClass x:Key="BorderConverter" /> 

Finally, i apply to Border element. And SettingThumbWidth is a TextBox element.

<Border  Width="{Binding Path=Text , ElementName=SettingThumbWidth, Converter={StaticResource BorderConverter}}" Height="166" >

When i press "." after BorderConverter, the subclass PhotoBorderConverter won't show and it seems i cannot access.

So how can i fix this?

It because it possible have other Converter, so i want to centralized in one ConvertClass.

Thanks you.

Community
  • 1
  • 1
Cheung
  • 15,293
  • 19
  • 63
  • 93

1 Answers1

1

Your decision to centralize into ConverterClass is kind of weird and unnecesary. You can keep all your converters in one file, but you don't need to encapsulate them within an outer class.

With what you currently have, try using the correct namespace like this:

xmlns:converters="clr-namespace:GapView.Classes.ConverterClass"


<converters:PhotoBorderConverter x:Key="BorderConverter" />
slugster
  • 49,403
  • 14
  • 95
  • 145
  • It compile error and said: "A using namespace directive can only be applied to namespaces; 'GapView.Classes.ConverterClass' is a type not a namespace." But i agree with you, encapsulate within parent class is unnecessary in this case. I make change and put all the converter class just inside the Namespace. Rebuild and work perfect. Thanks you for correction. – Cheung Jan 28 '14 at 06:21