Live Chat Icon For mobile
Live Chat Icon

What is the use of a ControlTemplate ?

Platform: WPF| Category: ControlTemplates

It allows you to specify the visual structure of a class. The main advantage is we can override the default ControlTemplate defined in the control and replace it with new ControlTemplates, to reconstruct the visual structure of the class.

The following code illustrates the ControlTemplate of a button.

[XAML]

      <Style TargetType='Button'>
        <!--Set to true to not get any properties from the themes.-->
        <Setter Property='OverridesDefaultStyle' Value='True'/>
        <Setter Property='Template'>
          <Setter.Value>
            <ControlTemplate TargetType='Button'>
              <Grid>
                <Ellipse Fill='{TemplateBinding Background}'/>
                <ContentPresenter HorizontalAlignment='Center'
                                  VerticalAlignment='Center'/>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>

Share with

Related FAQs

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

Please submit your question and answer.