Control Templating: One of the Most Powerful WPF Features! (KevinButton example)
A few weeks ago there was a good humored Channel 9 video named “Reskin Your Application with the KevinButton”. While the video is lighthearted, it makes a very important point: Control templates are one of the most powerful and important reasons why we should all look at WPF as our future development platform. I’ve had discussions with many people who are just starting to look seriously at WPF. Their initial response to the new platform is very similar and can be summed up by, “WPF has some cool features and nice eye-candy, but I don’t find it particularly ground-breaking.” Invariably these same people completely reconsider their initial impressions once they “get” what control templates are all about.
To get an understanding of exactly why control templates are so powerful you need to know that, with a very few exceptions, in WPF controls do not own their presentation. The presentation of a control is almost completely separated from the business logic of that control. By using a control template the presentation can be overridden to be almost anything.
In the Channel 9 video, Kevin Moore and Robby Ingebretsen create a new button template that animates a button using a grid, some rectangles and a few images. Check out the video. I was unable to find the source code for their example so I quickly created a similar SmileyButton xbap example for everyone to peruse. Just click on the picture below to run the xbap app. This does exactly the same thing as the KevinButton, but using different images. The smiley will animate according to which part of the button the mouse is over. This has been built using the July CTP.
If you haven’t had a chance to watch the video, the important thing to note about this example is that the single control in the application is a button: it captures and hooks into all the events and methods that a standard button inherits. It just has its presentation changed to be something other than the default.
The xaml source code for this WPF example can be found in the next post.
August 29th, 2006 at 3:32 am
[…] XamlXaml.com Exploring XAML and WPF « Control Templating: One of the Most Powerful WPF Features! (KevinButton example) […]
August 29th, 2006 at 5:30 pm
It appears xbap settings arent being rendered properly? At least ie+july ctp isnt launching as a xaml page.
August 29th, 2006 at 6:36 pm
Thanks for the info Ronald. I wasn\’t aware of this…it serves up fine on my Vista OS, but not on my XP + .NET OS. I am looking into the problem and hope to have it resolved shortly.
September 14th, 2006 at 8:43 am
Thank you very much for this sample but it need a password to run (test_TemporaryKey.pfx). Is it normal?
If you want I can make the vectorial design for your smiley.
September 15th, 2006 at 5:54 pm
XBAP application manifests must always be signed. If you open the csproj in Visual Studio 2005, go to project properties/signing you will see the certificate under the “Sign the ClickOnce manifests”. You can delete the temporary one included in the project and chose “create test certificate” to create your own.
Alternately, if you want to run the application locally you can simply change the deployment settings to deploy as a standalone application rather than a web browser application.
As a final note, you can see the manifest reference in the csproj file if you edit it with a text editor. It will show up as:
Hope this help!
-MGE
September 21st, 2006 at 4:07 am
KevinButton sample code is now live: http://blogs.msdn.com/okoboji/archive/2006/09/20/764019.aspx