StrataFrame Forum

ThemedContainer BodyHiddenEventHandler question

http://forum.strataframe.net/Topic29150.aspx

By Keith Chisarik - 12/2/2010

I have a form on which I dynamically create X number of ThemedContainer controls, I add a handler for the BodyHidden event on creation of the control but the delegate BodyHiddenEventHandler does not  have a signature that includes sender. When the events fires I dont know which themedcontainer was collapsed.

I want to show the TitleImage when the body is collapsed and hide it when it is expanded. How can I accomplish this?

By Greg McGuffey - 12/3/2010

The typical way to handle this is to just have a handler for each container. That won't work if you are dynamically creating them (I'm assuming you mean you create them via code at runtime). So, what comes to mind is to create a class for the handler. It would have properties for any items you need access to in the handler and a public methods for the handlers (one for BodyHidden and one for BodyRestore).

public class ContainerImageSwitcher
{
     /// <summary>
     /// Require that a ThemedContainer be provided in constructor.
     /// </summary>
     public ContainerImageSwitcher(ThemedContainer container)
     {
          this.Container = container;
     }

     public property ThemedContainer Container { get; set;}

     public void HandleHidden() { //-- show image, using this.Container }

     public void HandleRestore() { //-- hide image, using this.Container }

}


Now in your code that creates the ThemedContainers and sets the handlers you can use the class:

private ThemedContainer BuildContainer()
{
    ThemedContainer newContainer = new ThemedContainer();

    //-- Setup as appropriate....

    //-- Add handlers
    ContainerImageSwitcher switcher = new ContainerImageSwitcher(newContainer);
    newContainer.BodyHidden += switcher.HandleHidden;
    newContainer.BodyRestore +=
switcher.HandleRestore;

   //-- Return container
   return newContainer;
}


I haven't tested this, but it should work.
By Keith Chisarik - 12/3/2010

Yes, they are created via code at runtime. I will try your suggestion, thanks.
By Greg McGuffey - 12/3/2010

Let us know how it goes! BigGrin