Partager via


Master-Detail With CollectionViewModel

Implementing a Master-Detail style UI with the CollectionViewModel I described in my previous post is pretty easy. With a selector control bound to a CollectionViewModel as shown in my previous post, you just need to add a content control to the View and bind its Content property to the current item and define how you want it to be rendered by defining a data template.

For the sample in my previous post the view's XAML contains this:

 <ContentControl Content="{Binding Path=Catalog.CurrentItem}">
     <ContentControl.ContentTemplate>
         <DataTemplate>
             ...
         </DataTemplate>
     </ContentControl.ContentTemplate>
 </ContentControl>

Note: In WPF, you strictly only need to bind the content control's Content property to the Catalog - WPF automatically binds to the Catalog's current item for you. Not sure why they did it this way. I think an explicit binding to the CurrentItem property is easier to understand, and I don't mind typing the extra characters. Sometimes a little more is definitely more :-)

You can run the updated sample here and download the updated source here. I also updated it to use the final release assemblies from Prism 2.0, and fixed a glitch in the Silverlight Unit Testing assembly references...

Comments

  • Anonymous
    February 20, 2009
    The comment has been removed

  • Anonymous
    February 21, 2009
    Thank you for submitting this cool story - Trackback from DotNetShoutout

  • Anonymous
    February 23, 2009
    Hey Joe - Doh! You're right. Many thanks for tracking this down. I added your fix to the CollectionModelView class. David.