ボタンコマンドにバインドしている場合、カスタムタイプを ICommand に変換する TypeConverter を作成しようとしています。
残念ながら、WPF は私のコンバーターを呼び出していません。
コンバータ:
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}" />
次のようなコンテンツにバインドすると、コンバーターが呼び出されます。
<Button Content="{Binding CustomObject}" />
TypeConverter を機能させる方法はありますか?