c# - Using Usercontrol inside Datatemplate -
on project have started using caliburn.micro
.
now want split large usercontrol
several smaller usercontrols
, can use them inside of datatemplates
. eisenbergeffect suggests in answer
the viewmodels
there, modelled hierachical data observablecollection<subviewmodel>
.
now thought have create suiting views
usercontrols
subviewmodels
.
my view master-details view. want present list of computers , in details view want have hardwarecomponents of those.
<listview x:name="computerviewmodels"> <listview.itemtemplate> <datatemplate> <contentcontrol x:name="hardwarecomponentviewmodel" /> </datatemplate> </listview.itemtemplate> </listview>
i have included debug output suggested here: debug logging
and not output hardwarecomponentviewmodel except action convention not applied: no actionable element set_hardwarecomponentviewmodel
the hardwarecomponentviewmodels created time computerviewmodels created.
i use contentcontrol
- way on other parts of application , works there (getting content
using ioc injected outer viewmodel). not seem fit datatemplate part (which not surprising, though). subviewmodels derived screen
, outer viewmodels.
how can use new usercontrol datatemplate?
take close @ eisenbergeffect's answer. it's explicitly stated, conventions don't work inside datatemplate
, if have complicated template, it's better move out separate usercontrol
, inside conventions work again.
that means have explicitly bind model inside template:
<listview x:name="computerviewmodels"> <listview.itemtemplate> <datatemplate> <contentcontrol cal:view.model="{binding hardwarecomponentviewmodel}" /> </datatemplate> </listview.itemtemplate> </listview>
that should it. either or cal:model.bind="{...}"
, can never remember difference , use case. inside bound usercontrol
(hardwarecomponentview
, presume) conventions between view , view model should work usual.
Comments
Post a Comment