How to stop Workspace.Show activating SmartPart?

Topics: CAB & Smart Client Software Factory
Aug 16, 2006 at 2:29 AM
originally posted by: limepickle

I have a smartpart I want to show in Workspace B when (and only when) a certain type of child workitem is active in Workspace A. So I hook Workspace A's SmartPartActivated event on the parent workitem like this:

WorkItem.WorkspacesA.SmartPartActivated += new EventHandler<WorkspaceEventArgs>(SmartPartActivated);

void SmartPartActivated(object sender, WorkspaceEventArgs e)
{
if (e.SmartPart.GetType() == typeof(MyView))
{
WorkItem.WorkspacesB.Show(mySharedSmartPart);
}
else
{
WorkItem.WorkspacesB.Hide(mySharedSmartPart);
}
}

The problem is that Workspace.Show activates a smartpart that's already contained in its smartparts collection:

// Workspace.cs in CAB
public void Show(object smartPart)
{
...
if (smartParts.Contains(typedSmartPart))
{
Activate(smartPart);
}
else
{
...
}
}

This isn't what I want; I want to keep the current view in Workspace A (which contains the main workitems) active.

How can I do that?
Aug 16, 2006 at 5:43 AM
originally posted by: JKraft4PIT

--------------------------------------------

The problem is that Workspace.Show activates a smartpart that's already contained in its smartparts collection:

--------------------------------------------

Of course it is you asked it to show the part, and it shows it by activating it if it is in it's collection already like the code says. When are you calling show because your sample code looks fine.

But if you want to stop it from activating it then take out the descision code in CAB that you showed and just call activate when you want to "Show" a smart part . But if you don't want to do that then make your own workspace and override that method on CAB. Which ever works for you.
Aug 16, 2006 at 5:52 AM
originally posted by: JKraft4PIT

I replyed to quickly, I think I see that you don't want it to activate the smart part you are showing you just want to see it.
Well like I say at the end of my last post, just remove the activate code and do it manually, but the activate is how it displays the smartpart.
Are you having a event firing problem?
Aug 16, 2006 at 7:06 AM
originally posted by: limepickle

Thanks for the reply.

As you said, I don't want to activate the smart part, I just want to make sure it's visible in workspace B whenever certain type of view is active in workspace A. And I want to make sure workspace B hides it otherwise.

Therefore, I hook the SmartPartActivated event in the WorkItemController that shows smart parts in workspace A. Whenever a smart part of the right type is activated in workspace A, I show my smart part in workspace B; otherwise, I hide it.

You say I should remove the activate code but that code is in the CAB Workspace class. Are you saying that I need to derive a new workspace and override the Show method so that it doesn't automatically activate the smart part?

thanks again
Aug 16, 2006 at 7:09 AM
originally posted by: JKraft4PIT

Exactly, the only thing is that I am not sure the smartpart will show without the Activation code. I beleive the actually viewing of the part is in that code, but I beleive that is dependent on the Workspace you are using.
What type are you using? Deck, tab, window?
Tell me and maybe I can do a couple test.
Aug 16, 2006 at 7:42 AM
originally posted by: limepickle

My workspace (workspace B) is an Infragistics UltraDockWorkspace.

I just had another thought...is there some way I can trick the ControlActivationService into not activating the workitem when mySmartPart is shown?

Wow...I got up this morning thinking I'd have a nice easy day of coding...:S
Aug 16, 2006 at 8:02 AM
originally posted by: JKraft4PIT

Do you have access to the UltraDockWorkspace source code?
If not then I will spend time on other ideas.
Aug 16, 2006 at 8:11 AM
originally posted by: limepickle

Yes.

(I think it's possible to download it from their website too.)
Aug 16, 2006 at 9:00 AM
originally posted by: limepickle

This seems to work but it seems a long way from elegant.

bool showingSmartPart; // false initially

void SmartPartActivated(object sender, WorkspaceEventArgs e)
{
if (e.SmartPart.GetType() == typeof(MyView))
{
if (!showingSmartPart)
{
WorkItem.WorkspacesB.Show(mySmartPart);
showingSmartPart = true;
}
}
else
{
if (showingSmartPart)
{
WorkItem.WorkspacesB.Hide(mySmartPart);
showingSmartPart = false;
}
}
}
Aug 18, 2006 at 1:21 AM
originally posted by: limepickle

I finally created a new docking workspace with my own implementation of Show that does not call Activate but does call OnShow. This is better but I had to reproduce a lot of code that the Infragistics UltraDockWorkspace uses to do it. I'll look for more concise solution when I get time.
Aug 18, 2006 at 5:20 AM
originally posted by: JKraft4PIT

That is the only way that i can think of doing it to keep the way you are coding right now the same. (using the OnActivate event)