Well, I just don't declare them in xaml at all. Instead, I additionally derive a converter of mine from MarkupExtension
. Like this:
public class MyValueConverter : MarkupExtension, IValueConverter
{
private static MyValueConverter _converter = null;
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (_converter == null) _converter = new MyValueConverter();
return _converter;
}
public object Convert
(object value, Type targetType, object parameter, CultureInfo culture) { }
public object ConvertBack
(object value, Type targetType, object parameter, CultureInfo culture) { }
}
This allows me to use my converter anywhere, like this:
Source="{Binding myValue, Converter={converters:MyValueConverter}}"
where converters is the namespace in which I have declared my converter.
Learned this trick from an old stackoverflow thread only.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…