c# - Using a Generic IValueConverter from XAML -


i have generic class implementing ivalueconverter. like:

class myvalueconverter<t> : ivalueconverter 

with xaml 2009, can use this:

<my:myvalueconverter x:typearguments='x:string'/> 

but apparently that's not allowed "compiled" xaml (i guess we'll have wait .net 5)

my current workaround subclassing each usage:

class foomyvalueconverter : myvalueconverter<foo> 

is possible in markup using xaml 2006?

you custom markupextension(archive)(v4). like:

public class mymarkupextension : markupextension {      public mymarkupextension() {         this.type = /* default type */;     }      public mymarkupextension(type type) {         this.type = type;     }      public type type { get; private set; }      public override object providevalue(iserviceprovider serviceprovider) {         type type = typeof(myvalueconverter<>).makegenerictype(this.type);         return activator.createinstance(type);     } } 

then you'd use {binding ... converter={local:mymarkup {x:type bounceease}}}


Comments