Creating composite components.

Let's create three components one to write "Hello", one to write "World" and one to write "Hello World". All three components will be WebComponent inheritors.

 

public class HelloComponent : WebComponent

{

  public override void OnInitializing()

  {

    base.OnInitializing();

    Workspace.Controls.Add(new LiteralControl("Hello"));

  }

}

 

public class WorldComponent : WebComponent

{

  public override void OnInitializing()

  {

    base.OnInitializing();

    Workspace.Controls.Add(new LiteralControl("World"));

  }

}

 

public class HelloWorldComponent : WebComponent

{

  public override void OnInitializing()

  {

    base.OnInitializing();

   

    // Create placeholder for 'Hello' components

    var helloPlaceholder = new PlaceHolder();

    Workspace.Controls.Add(helloPlaceholder);

 

    // Add space between 'Hello' and 'World'

    Workspace.Controls.Add(new LiteralControl(" "));

 

    // Create placeholder for 'World' component

    var worldPlaceholder = new PlaceHolder();

    Workspace.Controls.Add(worldPlaceholder);

 

    Children.Add(new HelloComponent {Workspace = helloPlaceholder});

    Children.Add(new WorldComponent {Workspace = worldPlaceholder});

  }

}



I.e parent component can specify Workspace for child components; analogically View of parent component can specify Workspace for children components' View. See, workspaces for details.