September 05, 2006

WPF - Lookless Controls

Lookless Controls

  • you can easily customize the entire appearance of a control without the need to write a custom control.

  • usually have a built-in template that provides a default appearance, however, you can replace this template to change the look of the control.
  • most controls are lookless because WPF disassociates the appearance from the control.

Example:

<Page x:Class="TestXBAP.Page1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Page1" Height="100" Width="200">

<Button>

<Button.Template>

<ControlTemplate>

<Grid>

<Rectangle Fill="Bisque" Stroke="DarkRed" RadiusX="5" RadiusY="3" />

<ContentPresenter Content="{TemplateBinding Button.Content}"

HorizontalAlignment="Center" VerticalAlignment="Center"/>

<Ellipse Fill="Azure"/>

<ContentPresenter Content="{TemplateBinding Button.Content}"

HorizontalAlignment="Center" VerticalAlignment="Center"/>

</Grid>

</ControlTemplate>

</Button.Template>

Click me! I'm Button!!

</Button>

</Page>