Different Views on ContentControl

Topics: Conventions, Getting Started, UI Architecture
Oct 30, 2011 at 7:47 AM

Hi everybody,

I have to start my first WPF-Project and I will use MC for this. I'm not sure if it's a good idea to learn WPF-convention and CM-conventions together, but I want to skip the learningtime of WPF alone.
So I hope my questions sounds not to stupid and you excuse if the question is more a WPF question as a CM question.

I start with a (at start) simple SDI project. My shell has three regions (MenuView on Top, StatusBar on Bottom and a content region between)
Menu and statusbar I bind over Convention with properties in the ShellViewModel, but the content should be binded by Action from a menu-selection.
None of the examples I've seen use the old menustyle look, only fancy buttons.
How to select the region to load the view into a special region?

And at this point seems the next question to be equal.
One of this views should show an option-dialog, left side a tree or an list, right side the content to fill. At any selection on the left side, the right side should load the special view for the selection.

I have not found a example for this or I have not found the right keywords for this search ;)

Can anybody point to an example so I can learn this basics?

Regards,

Wolfgang

Oct 30, 2011 at 5:30 PM
Edited Oct 30, 2011 at 5:31 PM

Look into the Caliburn ActionMessage along with an interaction trigger. For normal buttons you just name the button the name of your method and caliburn will wire this all up for you through convention, not sure if it'll pick up menu items. But sans the conventions the ActionMessage will work perfectly.

Now, to load the region consider having the region (a content control) named ActiveItem, ie (x:Name='ActiveItem'), on the ShellView. Then, to load the region, when the method from the menu item action is called Activate an view model of the region you want to load. Caliburn will wire the view up for you. The method will be something like this, oversimplified:

 

        public void LoadRegion()
        {
            var region = new RegionViewModel();

            ActivateItem(region);
        }

 

 

 

Oct 30, 2011 at 6:31 PM

Thanx for your answer, but I'm now a little bit more confused :(

I don't have buttons with any names, or do you mean, that the menu-item should have a button with the name of the method?

And for the second part: who is calling the method LoadRegion and why should CM know, that I want to load into ContentControl with name ActiveItem? Is this a convention that by calling ActivateItem() into the 'ActiveItem' will be loaded?
And must the inner ContentControl in a View have also the name ActiveItem to load in it (Options)?

Maybe you have an full example so i can watch and search for the names for the convention.

Oct 31, 2011 at 11:44 PM

this might help better,

All about actions:

http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation

Screen/Region Stuff:

http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition&referringTitle=Documentation

Nov 1, 2011 at 10:21 AM

That was the first location I looked for an answer before I asked here. I am shure, this is the answer, but I can not combine the different pieces of code togheter. p.ex. action in the MenuViewModel as action to load a ViewModel in the contentcontrol of another view.
And that is only the easiest way, I'm going to understand the framework. In future, the Menu should be created programmatically dependent from userlevel and other stuff. Then I think I have more other troubles, because binding by creation will not work.

Thank you for your help.

Nov 1, 2011 at 3:05 PM

You might want to have a gander at this discussion related to menuing

http://caliburnmicro.codeplex.com/discussions/254102

Nov 1, 2011 at 6:02 PM

Sorry, I don't understand the word 'gander'

This thread shows me, that other user can solve it. But not with CM-Utilities, with own written Interfaces to use CM. Showing interfaces like this, is for me like 4 wheels and no car to put it on.
I think now, CM is not a framework to build solutions, its a framework to build a own framework to build solutions.

I think, it was to early from me, to ask for a solution. I have not unerstood the basics of CM.
I will work on it and follow the questions and answers of the other users and try to find my framwork based on CM.

Thank you, all

Nov 1, 2011 at 10:44 PM
Edited Nov 1, 2011 at 10:55 PM

ah ok... Gander = Look at.

 

Based on what you asked at the top.  ContentControl just a place holder that is dynamic in the sense that currently "active" item.   This is achieved in a couple of ways.  
One that you hinted at above is assuming you are using Conductors.  A collection of them at that.  

Looking at the viewmodel for the shell (in the examples provided in the download) you will see some methods that will have ActivateItem(new SomeViewmodel());  in those methods.
 They are telling the ContentControl named "ActiveItem"  <ContentControl x:Name="ActiveItem" /> 
to have it's Content property assigned to a particular viewmodel.  ActivateItem is a method in Caliburn.Micro.

 

As for changing views on ContentControl you can also do something like this...

<ContentControl  cal:View.Context = "{Binding CurrentView, Mode=TwoWay}"
                          cal:View.Model = "{Binding}" />

All this is doing is allowing the property of type string,  selects a usercontrol, it is based off the current viewmodel you are using.   That usercontrol will be in the hierarchy of your project structure something like below

Views
   -> MainView (a sub folder)
    ---> SomeView.xaml (user control in the MainView subfolder)
   -> MainView.xaml (root of the Views folder)

 

Now in your viewmodel you will have a property CurrentView (of type string), it will be set to the name of the usercontrol you want displayed.  Logic will control what and when.  
CurrentView = "SomeView"   a very rough example.  if you want code I can post it tomorrow. 

MainView.xaml has the ContentControl as indicated above.  ViewLocator will traverse the namespaces and should produce this usercontrol and set the Content property of the ContentControl.

 

As for the menuing features, there isn't anything built into CM that will do this out of box.   You will have to write your own or reference the dicussion I suggested above.

Nov 2, 2011 at 7:38 AM

Hi, thank you for helpig me to understand CM.
I will try again the next time, but it is a private project and I have time only on weekends.

My Problem is to see the whole system assembled.
I have read in the documentation the real simple samples to bind a VM to ActiveItem (but not that is a convention between the name 'ActiveIten' and the Method 'ActivateItem'), then I have read from conductors and screencollection without any context to a project.
Then I see in the samples that some VM's are inheritet from Screen, Iscreen an whatever without explanation why this different ways.
I don't see a straight direction to follow, but so many ways to do it.
And by my luck, its sure that I follow the wrong way ;)