|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWindows Presentation Foundation allows the developer to completely change the look and feel of the controls. This is accomplished by using Control Templates. It means you can render your Why Control Templates and Why Not Styles?In one of the previous articles, we talked about Styles in WPF. You can check out the article: Introduction to Styling in Windows Presentation Foundation. One question you might ask is why not use styles to change the look of the controls. Styles can change the appearance of your control but they will be dependent on the properties provided by the control itself. It means you will not be able to render your Creating a Round ButtonIn this article, we are going to create a round <Button Content="Push Me!" >
This will create a very simple <ControlTemplate x:Key="buttonTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="el1" Fill="Orange" Width="100" Height="100">
</Ellipse>
</Grid>
</ControlTemplate>
The control template defined above is really simple! First a unique key “
Now, let’s apply the template to the <Button Content="Push Me!" Template="{StaticResource buttonTemplate}"
Click="Button_Clicked"></Button>
As soon as you apply the control template, the There is one problem with the above rendering; the content of the <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"
Content="{TemplateBinding Button.Content}" />
And here is the result:
We are not done yet! Let’s also add a trigger to the <ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="el1" Property="Fill" Value="Yellow"/>
</Trigger>
</ControlTemplate.Triggers>
The trigger is fired on the ConclusionWPF Control Template is a very important feature of the WPF Framework. It allows you to change the look and feel of the WPF controls and render them in completely different way from their default format. I hope you liked the article. Happy coding! History
|
||||||||||||||||||||||||||||||||||||||||