mvvm - Wpf Expander Collection, how to have parent ViewModel know which Expander object current? -
in view contains item having collection of child items, have itemscontrol hosts child items collection. individual items contained in expander. when child item expanded, need parent view model aware of child being acted upon. able implement event trigger passes child object parameter parent view model, , parent view model can set selectedchildobject property. need falls short when multiple items expanded, , user acts on item not in expanded item. when happens item interacting not match selectedchildobject property, since expanded object property value.
i have seen solutions use listbox contain expander, , set expander isexpanded based on listbox isselected, don't solution because allows 1 expander open @ time, plus not seem possible have expander stretch fill of space in listbox, , not good.
is there way can let parent view model know child object being acted upon?
<itemscontrol grid.row="0" grid.column="0" itemssource="{binding slots, mode=twoway}"> <itemscontrol.itemtemplate> <datatemplate> <expander padding="10"> <i:interaction.triggers> <i:eventtrigger eventname="expanded"> <i:invokecommandaction command="{binding datacontext.expandedcommand, relativesource={relativesource ancestortype={x:type usercontrol}}}" commandparameter="{binding}" /> </i:eventtrigger> </i:interaction.triggers> <expander.header> <grid> <grid.columndefinitions> <columndefinition width="32" /> <columndefinition width="*" /> </grid.columndefinitions> <image grid.row="0" grid.column="0" height="16" width="16" source="/wpfapp1;component/assets/images/warning.ico" /> <stackpanel grid.row="0" grid.column="1" orientation="horizontal"> <label content="slot: " /> <label content="{binding slotnumber, mode=twoway, validatesonnotifydataerrors=false}" /> </stackpanel> </grid> </expander.header> <stackpanel margin="20"> <stackpanel orientation="horizontal"> <label content="slot number:" margin="0 5 2 0" width="100" /> <textbox text="{binding slotnumber, mode=twoway, updatesourcetrigger=propertychanged, validatesondataerrors=true, validatesonexceptions=true, validatesonnotifydataerrors=true, notifyonvalidationerror=true}" style="{dynamicresource configuration.input.textbox}" width="30" /> </stackpanel> <stackpanel orientation="horizontal"> <label content="modules:" margin="0 5 2 0" width="100" /> <listbox itemssource="{binding source={x:static local:slotsviewmodel.allowedmodules}}"> <listbox.itemtemplate> <datatemplate> <checkbox content="{binding}" command="{binding datacontext.addremoveallowedmodulecommand, relativesource={relativesource ancestortype={x:type usercontrol}}}" commandparameter="{binding}"/> </datatemplate> </listbox.itemtemplate> </listbox> </stackpanel> </stackpanel> </expander> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
what kind of actions trying perform on slots?
something removing last manipulated slot? if have write behavior or control capture previewmousedown events , send command/event notify parent view model. it's not ideal.
and way want "selected slot" highlighted befor can removed. try remove background of expander , use listbox. when click on background of slot selects , highlights listboxitem. in way can bind selecteditem vm.
Comments
Post a Comment