New Posts New Posts RSS Feed: Cocktail 2012 - IWorkspace  Why that change
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cocktail 2012 - IWorkspace Why that change

 Post Reply Post Reply
Author
halloweenx8 View Drop Down
Newbie
Newbie
Avatar

Joined: 07-Sep-2012
Location: Longueuil, QC
Posts: 36
Post Options Post Options   Quote halloweenx8 Quote  Post ReplyReply Direct Link To This Post Topic: Cocktail 2012 - IWorkspace Why that change
    Posted: 26-Sep-2012 at 8:02am
Hi
 
I was using IWorkspace to dyamically create menu items after loading a XAP
 
       Composition.AddXapAsync("dymanicMenu.xap");
 
But it does not work anymore
 
Why the change to
         protected override void PrepareCompositionContainer(CompositionBatch batch)
        {
            base.PrepareCompositionContainer(batch);
            // Configure workspaces
            batch.AddExportedValue<IWorkspace>(
                new Workspace("Home", true, 0, typeof (HomeViewModel)));
            batch.AddExportedValue<IWorkspace>(
                new Workspace("Resource Management", false, 10, typeof (ResourceMgtViewModel)));
        }
How do you now dynamically add workspaces, in my case I adding a XAP with a workpace in it would have done the trick, how do I do that with Cocktail 2?
 
Thanks
Jean

"If You are Not Making Mistakes, then You are Not Doing Anything.”
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2012 at 12:02pm
You can still dynamically add workspaces, but IWorkspace is no longer automatically exported in TempHire. The change above is due to how the Navigator works in Cocktail 2. You no longer navigate to an instance of a ViewModel. You navigate to a ViewModel type.
 
So, therefore IWorkspace was changed to return the associated VM type for the navigator. Because I only have two workspaces in TempHire I decided to statically add them directly to the container instead of creating Workspace classes that are exported.
 
The workspace is basically just a lightweight proxy now that knows the type of the ViewModel that implements the actual workspace. The shell grabs the type from the Workspace and navigates to it, so the VM and all it's dependencies are not instantiate until you navigate to the workspace.
 
In your case you have to create a class for each workspace and export it as IWorkspace, so that it gets discovered when you load the xap.
 
So, for example I could have done the following instead of adding the home workspace via the CompositionBatch.
 
    [Export(typeof(IWorkspace))]
    public class HomeWorkspace : Workspace
    {
        public HomeWorkspace() : base("Home", true, 0, typeof (HomeViewModel))
        {
        }
    }

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down