c# - wpf, register DP, bindable converter parameter -


[valueconversion(typeof(object), typeof(object))] public class bindableconvertor : dependencyobject, ivalueconverter {     public object bindableparameter     {         { return getvalue(mypropertyproperty); }         set { setvalue(mypropertyproperty, value); }     }      public static readonly dependencyproperty mypropertyproperty = dependencyproperty.register(             nameof(bindableparameter),             typeof(object),             typeof(bindableconvertor),             new propertymetadata(string.empty)             );       public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         // actions here...     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

xaml:

<application.resources>     <local:bindableconvertor x:key="myconvertor" bindableparameter="{binding anytargetproperty}" /> </application.resources> 

finally:

<listbox name="viewbox"                      grid.row="0"                      displaymemberpath="value"                      itemssource="{binding somepropertyfromwindowdatacontext,                                            converter={staticresource myconvertor}}" /> 

result: system.windows.data error: 2 : cannot find governing frameworkelement or frameworkcontentelement target element. bindingexpression:path=; dataitem=null; target element 'bindableconvertor' (hashcode=19986012); target property 'bindableparameter' (type 'object'). , "bindableparameter" equals default value (null).

but if like:

        <local:bindableconvertor x:key="myconvertor" bindableparameter="constant text here..." /> 

... works perfectly.

any ideas why?

it because converter inherits dependencyobject. try freezable instead.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -