mvvm - Injecting Instantiated ViewModel to View with AvalonDock -
i have observable collection of viewmodels bound avalondock's layoutitemtempate. when user opens problem fetched list, creates new viewmodel in observable collection. new document created result, new , not use viewmodel collection.
i tried use converter, doesn't seem use converter @ all. know alternative? perhaps code-behind solution?
here main xaml snippet . . .
<window.resources> <pconv:iprobleminfotofreeresponsevmconverter x:key="freeresponsetovm" /> </window.resources> . . . { lines down } . . . <dock:dockingmanager.layoutitemtemplateselector> <selector:layoutitem> <selector:layoutitem.problemeditviewtemplate> <datatemplate> <problem:freeresponseedit datacontext="{binding selectedproblem, converter={staticresource freeresponsetovm}}" /> </datatemplate> </selector:layoutitem.problemeditviewtemplate> </selector:layoutitem> </dock:dockingmanager.layoutitemtemplateselector>
my converter code . . .
[valueconversion(typeof(freeresponse), typeof(freeresponseeditviewmodel))] public class iprobleminfotofreeresponsevmconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { if (value freeresponse) return new freeresponseeditviewmodel(value freeresponse); return value; } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { if (value freeresponseeditviewmodel) return (value freeresponseeditviewmodel).problemitem; return value; } }
binding itemsource
stack of freeresponseeditviewmodel, datatemplate creates freeresponseedit
, injects freeresponseeditviewmodel
view datacontext automatically.
<dock:dockingmanager.layoutitemtemplateselector> <selector:layoutitem> <selector:layoutitem.problemeditviewtemplate> <datatemplate> <problem:freeresponseedit /> </datatemplate> </selector:layoutitem.problemeditviewtemplate> </selector:layoutitem> </dock:dockingmanager.layoutitemtemplateselector>
the datacontext
omitted altogether.
Comments
Post a Comment