wpf - PropertyGrid with custom Itemsource and Dependency Injection -


i'm using ninject in mvvm application contains xceed propertygrid. propertygrid should use custom itemsource 1 particular property defined attribute:

[itemsource(gettype(someobjectitemsource)]  

the someobjectitemsource.getvalues , need's access object created ninject

public function getvalues() itemcollection implements iitemssource.getvalues      fetch rootobject ninject kernel     extract list of someobject rootobject , return  end function 

as propertygrid not created ninject , ninject internally uses activator.createinstance without optional constructor parameters approach fails cannot pass reference ninject kernel or rootobject.

note: source of propertygrid looks this. activate.createinstance able use constructor, isn't implemented way.

private system.collections.ienumerable createitemssource() {   var instance = activator.createinstance( _attribute.type );   return ( instance iitemssource ).getvalues(); } 

alternatively possible use custom type editor using itypeeditor , binding editor property of instance created propertygrid. approach suggested here: http://wpftoolkit.codeplex.com/discussions/351513 , looks like:

public class someobjecttypeeditor   implements itypeeditor   public function resolveeditor(propertyitem propertyitem) frameworkelement     dim box new combobox() { _      .displaymemberpath = "someobject" _     }      dim itemsourcebinding = new binding("") { _         .source = mainwindow.listofsomeobject , _         .validatesonexceptions = true, _         .validatesondataerrors = true, _         .mode = bindingmode.oneway _     }   end function end class 

if want stick avoiding code behind feasible way see using property injection on mainwindow.listofsomeobject. not right me.

i guess such situations arise different controls well. there common, abstract approach on solving such issues wpf controls?

the cleanest solution found use editing template , bind property of viewmodel.

<xctk:editortemplatedefinition.editingtemplate>     <datatemplate>         <combobox name="combo" itemssource="{binding relativesource={relativesource findancestor, ancestortype={x:type window}}, path=datacontext.listofsomeobject}"                                              displaymemberpath="objectname"                                              selectedvaluepath="objectid" />     </datatemplate> </xctk:editortemplatedefinition.editingtemplate> 

using approach listofsomeobject can created using property injection or directly constructor injection.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -