c# - Using caliburn.micro with hierachical viewmodel structure -


in project use caliburn.micro mvvm framework.

now have big viewmodel master-details view.

it hierarchically built.

just have example:

i have computerview computerviewmodel. works fine here.

now computerviewmodel contains observablecollection<hardwarecomponentviewmodel>

this hardwareviewmodel has no view attached, there keep data in place. caliburn not set binding correctly here. (i cannot use x:name binding)

until now, no problem use "normal" binding way. need add actionmessage grid in hardwarecomponentviewmodel.

to make more clear mean, here full xaml reproduce it

<usercontrol x:class="demoapplication.views.computersview"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:cal="http://www.caliburnproject.org"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:i="clr-namespace:system.windows.interactivity;assembly=system.windows.interactivity"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              xmlns:s="clr-namespace:system;assembly=mscorlib"              d:designheight="300"              d:designwidth="300"              mc:ignorable="d">     <grid>         <grid.resources />         <grid.rowdefinitions>             <rowdefinition height="10*" />             <rowdefinition height="2*" />             <rowdefinition height="1*" />         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition width="1*" />         </grid.columndefinitions>          <border horizontalalignment="stretch"                 borderbrush="transparent"                 borderthickness="0">             <scrollviewer horizontalcontentalignment="stretch"                           background="yellow"                           borderbrush="transparent"                           borderthickness="0"                           cancontentscroll="true"                           horizontalscrollbarvisibility="auto"                           verticalscrollbarvisibility="auto">                 <listview x:name="computers"                           horizontalcontentalignment="stretch"                           background="red"                           borderthickness="0">                     <listview.itemtemplate>                         <datatemplate>                             <border background="transparent"                                     borderbrush="transparent"                                     borderthickness="0">                                 <listview horizontalcontentalignment="stretch"                                           background="black"                                           itemssource="{binding hardwarecomponents}">                                     <listview.itemtemplate>                                         <datatemplate>                                             <border background="aquamarine"                                                     borderbrush="darkgray"                                                     borderthickness="1">                                                 <grid background="lime" cal:message.attach="[event click] = [action expand($datacontext)]">                                                     <grid.rowdefinitions>                                                         <rowdefinition height="20" />                                                     </grid.rowdefinitions>                                                 </grid>                                             </border>                                         </datatemplate>                                     </listview.itemtemplate>                                 </listview>                             </border>                         </datatemplate>                     </listview.itemtemplate>                 </listview>             </scrollviewer>         </border>     </grid> </usercontrol> 

update

1. have tried cal:bind.model="{binding}" on usercontrol, no effect took them question here

2. in grid tried: cal:message.attach="[event click] = [action expand]" did not work either

3. added logging ,

action convention not applied: no actionable element expand.

but not know tries tell me. perhaps no action can applied grid?

4. have bound button inside grid, works. parameter pass datacontext, indeed hardwarecomponentviewmodel, bubbled outside viewmodel, binding set correctly (computerviewmodel).

<button cal:message.attach="[event click] = [action expand($datacontext)]"> 

so question is: have binding set correctly? have actionmessages in hardwarecomponentviewmodel called?

have tried

cal:action.targetwithoutcontext="{binding datacontext}"

on button/grid/wherever need it? expect target of action current binding default, may not (not sure how cm wires up, might @ source). regardless, cm needs know target try bind action (the vm) , due not being bound standard cm way guess wiring can't done automatically , need explicitly bind using above code


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -