Replacing the control template of a progress bar
WPF prides itself on separating appearance from behavior. This is more evident with control templates than anything else. A control template is just that: a template for a control's appearance, which does not affect its behavior. In this recipe, we'll take a look at the basics of writing a control template by creating a custom template for a ProgressBar
control. In later recipes we'll discuss other, more complex control templates.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create an alternative control template for a ProgressBar
to demonstrate the basics of control template authoring:
Create a new WPF application named
CH08.CustomProgressBar
.Open
App.xaml
. Add a new resource of typeControlTemplate
as follows:<ControlTemplate TargetType="ProgressBar" x:Key="pt1"> </ControlTemplate>
Inside the
ControlTemplate
add the following markup:<Grid> <Rectangle x:Name="PART_Track"> <...