Tôi đang cố gắng tạo TypeConverter sẽ chuyển đổi loại tùy chỉnh của tôi thành ICommand nếu tôi ràng buộc nó với Button Command.WPF không gọi TypeConverter khi DependencyProperty là giao diện
WPF không may là không gọi công cụ chuyển đổi của tôi.
Chuyển đổi:
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}" />
Chuyển đổi sẽ được gọi nếu tôi sẽ liên kết với nội dung như:
<Button Content="{Binding CustomObject}" />
Bất kỳ ý tưởng làm thế nào tôi có thể nhận được TypeConverter làm việc ?
Rất thú vị. Tôi đã xác nhận rằng loại giao diện là một vấn đề. Mã thử nghiệm: http://pastebin.com/EsMguMx5 - trình biến đổi không bao giờ được gọi, nhưng chỉ cần thay đổi 'IDestinationThing' thành' DestinationThing' trong định nghĩa thuộc tính phụ thuộc và nó sẽ bắt đầu hoạt động. – nmclean