I am trying to create a TypeConverter that converts my custom type to ICommand if I bind it to Button Command.
Unfortunately, WPF does not call my converter.
Converter
public class CustomConverter : TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(ICommand)) { return true; } return base.CanConvertTo(context, destinationType); } public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(ICommand)) { return new DelegateCommand<object>(x => { }); } return base.ConvertTo(context, culture, value, destinationType); } }
Xaml:
<Button Content="Execute" Command="{Binding CustomObject}" />
The converter will be called if I get attached to the content, for example:
<Button Content="{Binding CustomObject}" />
Any ideas how I can get TypeConverter to work?
source share