c# - WPF not calling TypeConverter when DependencyProperty is interface -


i trying create typeconverter convert custom type icommand if binding button command.

unfortunetly wpf not calling 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}"  /> 

converter invoked if bind content like:

<button  content="{binding customobject}"  /> 

any ideas how can typeconverter work?

you can if create itypeconverter. you'll have use explicitly, more xaml write. on other hand, being explicit thing. if trying avoid having declare converter in resources, can derive markupextension. converter this:

public class tocommand : markupextension, ivalueconverter {     public override object providevalue(iserviceprovider serviceprovider)     {         return this;     }      public object convert(object value,                            type targettype,                            object parameter,                            cultureinfo culture)     {         if (targettype != tyepof(icommand))             return binding.donothing;          return new delegatecommand<object>(x => { });     }      public object convertback(object value,                                type targettype,                                object parameter,                                cultureinfo culture)     {         return binding.donothing;     } } 

and you'd use like:

<button content="execute"          command="{binding customobject, converter={lcl:tocommand}}" /> 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -