How can I create a ControlTemplate for a HeaderedItemsControl ?

Platform: WPF| Category: Templates

ControlTemplate can be created for a HeaderedItemsControl as follows.

[XAML]

<!--Define a control template for a HeaderedItemsControl-->
<Style TargetType='HeaderedItemsControl'>
  <Setter Property='Template'>
    <Setter.Value>
      <ControlTemplate TargetType='{x:Type HeaderedItemsControl}'>
        <StackPanel>
          <Grid>
            <Rectangle Fill='{TemplateBinding Background}'/>
            <ContentPresenter ContentSource='Header'/>
          </Grid>
          <Grid>
            <Rectangle Stroke='{TemplateBinding BorderBrush}'/>
            <ItemsPresenter Margin='2,0,0,0'/>
          </Grid>
        </StackPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

...

<HeaderedItemsControl  xmlns:sys='clr-namespace:System;assembly=mscorlib'
                       Header='My colors'
                       Background='SteelBlue'
                       BorderBrush='DarkSlateBlue'>
  <sys:String>Red</sys:String>
  <sys:String>Yellow</sys:String>
  <sys:String>Blue</sys:String>
  <sys:String>Green</sys:String>
</HeaderedItemsControl>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.