How to add control to view

Topics: Mobile Client Software Factory
Apr 5, 2007 at 12:29 PM
Hi,

I am new to the CAB framework and am still trying to figure it out.
My first problem is, how to get a user control, which derives from the OrientationAwareControl but drag and drop doesn't work, and the examples i've seen all do it in a slightly different way.

thanks,

Manuel Silva
Apr 5, 2007 at 2:55 PM
Manuel,

More information is required. In CAB, UserControls are views. So the only dragging and dropping you should be doing is to drag a component onto a UserControl. If your UserControl inherits from another type of Control then that is all you need to do.

So, there's probably something I'm missing here. Throw some more information my way and maybe I can help :-)
Apr 5, 2007 at 3:24 PM
this is my view:

public partial class TestModuleView : Form, ITestModuleView
{
public TestModuleView()
{
InitializeComponent();
}

}

and i have a usercontrol:


public partial class TestModuleControl : OrientationAwareControl
{
public TestModuleControl()
{
InitializeComponent();
}
}

which i would like to use in the view. there is an example, i think it's in HOL4 were u create a usercontrol and put it in a view, but... it doesn't tell u how it's put in the view.

thanks
Apr 5, 2007 at 4:54 PM
Manuel,

You cannot use Forms with CAB. Your TestModuleView is inheriting from the wrong base class. It needs to inherit from UserControl. The CAB framework is designed to use UserControls as views, and those get shown in Workspaces (there are many types).

I would suggest downloading the Smart Client Software Factory (SCSF) and taking a look at some of the documentation for CAB so you get a better idea of how things fit together.

If you need a starter application, I can probably provide you with one.

Apr 5, 2007 at 5:16 PM
I need one badly.

The thing is the Add View with Presenter recipe creates a form! not a user control. I am so lost with this!!!
and in the adventureworks example, the forms also inherit from form.
i really don't understand how this works
Apr 6, 2007 at 12:52 AM
The Shell will be the only thing is a Form.

I'll try and get you a sample in a day or two. How's that sound?
Apr 6, 2007 at 7:39 PM
sounds great!
Apr 6, 2007 at 7:51 PM
Chris, you are wrong. You can use Forms in CAB. Your statement is absolutly incorrect that - Shell is the only form exist in CAB. You can have many forms in CAB and you can use as the workspaces. Create a form and derive from WindowWorkspace or any other workspace which suites your form needs. Create a instance of form and add into workspaces collection. Host controls on it. You can launch your forms from CAB shell or directly (without shell as a parent).

FYI - You can also develope a workspace to accept a form as a smart part. Basically, In CAB, All UI parts fall into two categories - Workspaces (Composable/Non-composable), SmartParts. The Workspace additionally, should know how to render its controls. If you look at orginally the window hierarchy - its cascade of workspaces and smart parts. Workspaces can have collections of smart parts (user controls) and Smart parts can have a workspace as a child control. For example, Shell has one Panel (Smart part) hosts Window Workspace and it has child Panel (smart part) and this panel has TabWorkspace as a child and it has collections tab pages (Smart parts), etc...

Sample code snippet:

public partial class Form1 : WindowWorkspace
{
.......
}

//Add the form into Workspaces collection
this.WorkItem.Workspaces.AddNew<Form1>("MyForm");

//Create smart parts
BusinessModule1View1 smartPart = this.WorkItem.SmartParts.AddNew<BusinessModule1View1>();
ISmartPartInfo smartPartInfo = new SmartPartInfo();
smartPartInfo.Title = "BusinessModule1WorkItem";

//Show your smarts parts on your form
this.WorkItem.Workspaces"MyForm".Show(smartPart, smartPartInfo);

In this above scenario, TestModuleView can be derived from WindowWorkspace as shown in the code. And you can add TestModuleControl into the TestModuleView's SmartParts collection.

Regards,
Venkat Nataraj
Apr 6, 2007 at 10:39 PM

venkat wrote:
Chris, you are wrong. You can use Forms in CAB.


Technically, yes, you're can. You could use a Form with CAB to do just what you suggest - build a custom Workspace. But how many newbies (which the original poster admitted to being) are authoring custom Workspaces? I was trying to keep the context of the original question in mind when answering...

The default workspaces that ship with CAB are suitable for most people starting an inspection of the CAB. Typcially, when a newbie asks a question like this, they're trying to figure out how to display a view (smartpart). And because I think it's important for them to not get confused about what CAB is or isn't, I suggest to people to stop thinking in terms of classic Windows Forms. CAB's views (smartparts) are built on UserControls. That's what I was trying to get across with my reply.

Not that you can't use Forms with CAB - you can (as you suggest). But it seems like a really specific scenario to me, which I'm not sure a newbie would be interested in.

We've got new people to CAB where I work, who come from Windows Forms backgrounds, and it takes them a while to understand the way CAB works (workspaces + views instead of straight forms). So I'm a little familiar with the learning curve people have to climb to get productive with CAB. I was just trying to help the newb, not make some difinitive statement about what you can (or can't, or shouldn't) do with CAB.

Cheers!












Apr 6, 2007 at 11:09 PM
I'm lost, oh so lost!
I will have to try that code on monday, but i more or less understand it. The thing i really crave for is a tutorial on how to make an app that goes through all the steps, doesn't skip anything. I don't have any knowledge of CAB for windows , so i'm starting from scratch in a platform that already has it's nuances when u develop for it, so when demonstrations assume previous knowledge and skip some steps, i'm lost.
Apr 10, 2007 at 12:05 PM
I feel your pain manuel.
CAB is a solid framework(imho) but it takes some learning.
Apr 10, 2007 at 3:51 PM
It might be a solid framwork, but the information available isn't enough and the demos don't have anything explaining how they were built. Or i just haven't found it.
Apr 10, 2007 at 3:56 PM
I'd suggest taking a look at this:

http://www.razzaq.org/pub/framework_composite_application_block.pdf

It's a PDF that a Sal Razzaq created to help new people with CAB. I haven't given it a thorough look, but a cursory glance seems to suggest it could be worth viewing. It has a "Hello CAB" type of walkthrough for building a first sample CAB application. Running through that might be worth something to a newbie.

CAB is a very powerful framework. And with that sort of power comes a learning curve. But I think it is very worthwhile to learn how to use the CAB, because there's so many benefits to developing with it. I know in our shop we'd have a lot harder time building our application (which is quite large and will only get bigger) if we didn't have CAB to build it with.

For small applications you don't need a framework like CAB (an IoC framework like Castle Windsor might be enough). But for large scale applications with a lot of decoupled modules... I think CAB is ideal.

Apr 10, 2007 at 6:37 PM
Edited Apr 10, 2007 at 6:37 PM
After reading Chris's link, may be you can use this code project article sample code. It is a very simple application that hosts user control into workspace. Forget about Xaml since you are a beginner. You can try with some other workspaces in that sample.

http://www.codeproject.com/useritems/XamlWindowsInCAB.asp
Apr 11, 2007 at 12:40 PM
Thanks all for your help.
Regarding the Xaml example, i will have a look at it since that's another thing i actually want to do, using CAB in a window app, but for the moment i'm just using Mobile. I wonder sometimes if it wouldn't be easier to start using in Windows first and the Mobile.
Regardign the pdf ChrisHolmes sugested i had already printed it and browsed it, but haven't read it. (it's now on my desk for me to read)

I got a simple breakthrough although not an important one. I can now drag and drop user control to my views.
This was really annoying because some of the examples use this, the quickstart and some of the reading i did used this, User Interface Design Best Pratices for Mobile EnterPrise Application Development guide was one of them, and i just couldn't do it.
Created several projects, messed with smartparts attributes and God knows how many things, copied all i could from the examples that did work, but nothing. Until i changed the projects from a folder inside my solution to the root of the solution, restarted VS and voila.

Now i can go on to other things, because i've cleared this matter. But it does bug me on why this happens. Is this a VS thing? I've never come accross this, but my projects rarely use usercontrols.

Thanks
Mar 17, 2008 at 5:45 AM
Hi,


I have created a custom workspace using CAB. Now i want to display the custom workspace in my ShellForm. How can i do that ?


Thanks
Mar 18, 2008 at 4:32 PM

sunny0102 wrote:
Hi,


I have created a custom workspace using CAB. Now i want to display the custom workspace in my ShellForm. How can i do that ?


Thanks


Hi, to use your custom workspace follow these steps:

1-If your custom workspace is in a project that is contained in a solution folder it won’t appear in the toolbar, to solve it check this thread: User Control cannot automatically been added to toolbox.

2-Select the custom workspace in the toolbar and drop it on your ShellForm.

3-Find Constants\WorkspaceNames.cs in the Infrastructure.Interface project.

4-Add a new string constant with the name for the workspace.
public const string MainWorkspace = "MainWorkspace";

5-In the ShellForm’s constructor set the name of the workspace using the previous constant.
public ShellForm()
{
    InitializeComponent();
 
    _mainWorkspace.Name = WorkspaceNames.MainWorkspace;
}

6-Add the views for the workspace where you need it.
ShowViewInWorkspace<View1>(WorkspaceNames.MainWorkspace);

For more information, you may check these SCSF Help topics and links:
  • Smart Client Software Factory | Inspecting the Software Factory Assets | Application Blocks | Composite UI Application Block | Developing Applications Using the CAB | Creating a Shell
  • Smart Client Software Factory | Inspecting the Software Factory Assets | Application Blocks | Composite UI Application Block | Extending the composite UI Application Block | Building Custom Workspaces
  • Introduction to SmartParts and Workspaces
  • More detail on Workspaces and SmartParts

Please let me know if this helps.

Jonathan Cisneros
http://staff.southworks.net/blogs/jcisneros/default.aspx