Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / HeaderedContentControl / HeaderedContentControl for WPF and Silverlight Task- Based Help / Adding Content to the Content Panel / Adding a Control to the Content Panel
In This Topic
    Adding a Control to the Content Panel
    In This Topic

    C1HeaderedContentControl will accept one child control in its content panel. In this topic, you will learn how to add a WPF button control in XAML, and in code.

    In XAML

    To add a button control to the C1HeaderedContentControl's content panel in XAML, complete the following steps:

    1. Place the following markup between the <c1:C1HeaderedContentControl> and </c1:C1HeaderedContentControl> tags:

      <Button Content="Click" Height="Auto" Width="Auto"/>
      
    2. Run the program and then expand C1HeaderedContentControl.

    In Code

    To add a button control to the C1HeaderedContentControl's content panel in code, complete the following:

    1. Add x:Name="C1HeaderedContentControl1" to the <c1:C1HeaderedContentControl> tag so that the control will have a unique identifier for you to call in code.
    2. Enter Code view and add the following code beneath the InitializeComponent() method:

      Visual Basic

      'Create the Button control
      Dim ContentButton As New Button()
      ContentButton.Content = "Click"
      
      'Set the Button Control's Width and Height properties
      ContentButton.Width = Double.NaN
      ContentButton.Height = Double.NaN
      
      'Add the Button to the content panel
      C1HeaderedContentControl1.Content = (ContentButton)
      

      C#

                
      //Create the Button control
      Button ContentButton = new Button();
      ContentButton.Content = "Click";
      
      //Set the Button Control's Width and Height properties
      ContentButton.Width = double.NaN;
      ContentButton.Height = double.NaN;
      
      //Add the Button to the content panel
      C1HeaderedContentControl1.Content= (ContentButton);
      
    3. Run the program and then expand C1HeaderedContentControl.

    This Topic Illustrates the Following:

    When C1HeaderedContentControl is expanded, the button control appears in its content panel and resembles the following image:

    Note that there isn't a header; this is because the Header property isn't set by default. To learn how to add text or controls to the header bar, see Adding Content to the Header Bar.