Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

21. Templates > An Example

An Example

image

To give you a taste for how control templates work, here’s a moderately complex example of a template that creates a round button with a shiny highlight. If you look at the XAML, you’ll see that the most complex part of the definition is the three gradient brushes. The rest is just a Border that contains a Grid with two ellipses. I don’t know about you, but I think that’s a pretty cool result for very little effort.

image

Put on Your Thinking Hat

image

Now it’s your turn...

1 Create a new project to contain the sample Button and rectangular version. You’ll want to move the brush definitions from the Resources section of the control template to Window.Resources so that you can reference them from both button templates.

image

2 Try changing the BorderBrush color of one of the buttons (the button itself, not the button’s control template). What happens?


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial