I need some clarification of the CM conventions

Topics: Conventions, Getting Started
Jun 29, 2012 at 7:35 PM


I've read, and re-read the documentation regarding Conventions and Screens, Conductors and Composition, but I'm in a fog.  Using the samples I've created a WPF application which is bootstrapped to an initial class that is a container with a design similar to an HTML page that has two frames.  A left frame for navigation, and a right frame for content.  CM's magic works great at initializing the container.  Where I'm stuck is with the TabControl.  Following the convention as stated here: [http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Conventions&referringTitle=Documentation] I have a ViewModel which is loaded to the "content frame".  The ViewModel has a TabControl with the x:Name property set to "Items".  The constructor of the ViewModel calls the ActivateItem method and passes a separate ViewModel which has a View that is a UserControl.  The UserControl is displayed in the tab, and it is properly wired to the associated ViewModel for that UserControl.  All of this functionality is working, but I don't know why.  If I change the x:Name property of the TabControl to anything else but "Items", then the automatic loading of the tabitems fails.

Specifically, this paragraph leaves me confused.  "So, for a named WPF TabControl we can conventionally bind in the list of tabs (ItemsSource), the tab item’s name (ItemTemplate), the content for each tab (ContentTemplate) and keep the selected tab synchronized with the model (SelectedItem). That’s not bad for one line of Xaml like this:"

Nowhere in the ViewModel that is associated with the TabControl is there a property or method called Items.  Yet, by calling ActivateItem and passing it a new class which itself is a ViewModel with an associated View the ItemsSource of the TabControl is populated.  Now, what if I wanted to access the SelectedIndex of the TabControl?  Would I use the ActiveItem property since that is associated with the Items property?  If so, to write the property ActiveItem in the ViewModel, what data type is Items?


Jun 29, 2012 at 8:38 PM

The Condcutor you are inheriting from has a collection called Items which the ViewModel gets added to when you call ActivateItem.