c# - How to set the binding of an itemscontrol to a different ViewModel? -


i've been trying bind list itemscontrol , continually come binding issues i've come help.

my code far is:

... <ssm:recentfilesviewmodel x:key="recentfilesvm" /> ...  <itemscontrol itemssource="{binding source={staticresource recentfilesvm}, path=files} margin="0 4 0 0">     <itemscontrol.template>         <datatemplate>             <telerik:radribbonbutton width="285">                 <textblock margin="0 0 0 2" text="{binding path}" />             </telerik:radribbonbutton>         </datatemplate>     </itemscontrol.template> </itemscontrol> 

i can list appear if set datacontext entire window means of other bindings don't work. object requires viewmodel want set unique itemscontrol. can please me working? it's driving me insane.

edit:

i have way because there no direct view model other objects. we're trying keep decoupled possible there no window datacontext. else works fine. using prism , telerik.

by adding binding source, of command bindings (which connect class in project) no longer work. there way can make sure binding source kept specific object manipulating?

add property recentfilesviewmodel inside viewmodel of window's datacontext.

then, can do:

<itemscontrol itemssource="{binding recentfilesviewmodel.files}" margin="0 4 0 0">     <itemscontrol.template>         <datatemplate>             <telerik:radribbonbutton width="285">                 <textblock margin="0 0 0 2" text="{binding path}" />             </telerik:radribbonbutton>         </datatemplate>     </itemscontrol.template> </itemscontrol> 

edit:

based on recent edit, can try wrapping itemscontrol in grid, , set datacontext recentfiles. note, not have create resource/key recentfiled, can access long namespace defined.

<grid>     <grid.datacontext>         <ssm:recentfilesviewmodel/>     </grid.datacontext>     <itemscontrol itemssource="{binding files} margin="0 4 0 0">         <itemscontrol.template>             <datatemplate>                 <telerik:radribbonbutton width="285">                     <textblock margin="0 0 0 2" text="{binding path}" />                 </telerik:radribbonbutton>             </datatemplate>         </itemscontrol.template>     </itemscontrol> </grid> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -