Jump to content
Xtreme .Net Talk

[C#] IComponentChangeService, ISelectionService & IDesignerHost


Recommended Posts

Posted

I'm doing this custom user control, I'm also working with designers and I need to use the Interfaces described in the topic subject. But I have a little situation. If any of those interfaces are not initialized somewhere in the code (ie: IComponentChangeService ICCS = (IComponentChangeService)GetService(typeof(IComponentChangeService))), I get an exception. But, I'm using these interfaces in lots of places in the code and in different classes, one of them doesn't even allow me to use the "GetService" method, it says it is not available in this context.

 

So, I'm looking for a way, to initialize these 3 interfaces just once and be able to use them everywhere I want. But I'm not being successful, how can I accomplish that?

Posted

Well, that's quite hard to do as the code is pretty big and separated in classes, I don't even know where to start showing a sample...

 

However, someone suggested me to override the ISite interface in the User Control code and something like this:

[csharp]public partial class PageStrip : UserControl

{

public override ISite Site

{

get { return base.Site; }

set {

base.Site = value;

 

if (base.Site == null) return;

 

Global.ICCS = (IComponentChangeService)GetService(typeof(IComponentChangeService));

Global.ISS = (ISelectionService)GetService(typeof(ISelectionService));

Global.IDH = (IDesignerHost)GetService(typeof(IDesignerHost));

}

}

}[/csharp]

Is working for now...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...