Print Page | Close Window

Create View on demand

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3435
Printed Date: 01-Sep-2025 at 10:29pm


Topic: Create View on demand
Posted By: rbautistaole
Subject: Create View on demand
Date Posted: 09-May-2012 at 1:41pm
Hi.
I´m creating an app using the TempHire demo as base.
In TempHire on the ShellViewModel the workspaces are collected and CREATED througout the MEF IOC. how you do build the same idea but not CREATING the WorkSpaces on app Start, but when the Toolbar to the View is pressed?
 
thanks in advanced.
Ramiro Bautista



Replies:
Posted By: mgood
Date Posted: 09-May-2012 at 2:57pm
Take a look at the very latest TempHire that ships with Cocktail v0.6. I've refactored the Shell to support lazy instantiation of workspaces. The Resource Management workspace is now created the first time you click on the button in the toolbar. The Resource Manager workspace is defined as a LazyWorkspace like so:
 
    public class StaffingResourceWorkspace : LazyWorkspace<StaffingResourceManagementViewModel>
    {
        public StaffingResourceWorkspace()
            : base("Resource Management", false, 10)
        {
        }
    }

IWorkspace now has a Content property that returns the actual workspace content, which in case of LazyWorkspace gets lazy instantiated upon first access.
 
    [InterfaceExport(typeof(IWorkspace))]
    public interface IWorkspace : IHaveDisplayName
    {
        bool IsDefault { get; }

        int Sequence { get; }

        IScreen Content { get; }
    }
LazyWorkspace just holds metadata about the workspace itself.
 
In the Shell, the NavigationService is then configured with a custom activator, which activates the content instead of the workspace itself.
 
            _navigationService = new NavigationService<IWorkspace>(this)
                .Configure(config => config.WithActivator(navigation => ActivateItem(navigation.Target.Content)));



Print Page | Close Window