Although there are many control models in Windows presentation Foundation, it is not possible to provide each of the controls you need. At this point, control authoring comes in handy. In this article, I'll show you how to customize an existing control using windows®presentation Foundation, and how to create an entirely new control (or element) for your project.
Before you develop a custom control, you should ask yourself if you really need it. In Windows presentation Foundation, the combination, styling, and templating features allow you to customize existing controls, which are unmatched by previous technologies. Before deciding to create a new control, let's quickly talk about the methods of these three custom controls.
Working with combinations
Creating a composite control is a common requirement. A composite control is a control that consists of more than one control. Suppose you have a play button to start the video playback. XAML and controls are shown in Figure 1.
Figure 1 Simple Play controls
<StackPanel>
<button height= "width=" "content=" Play "/> <polygon horizontalalignment=
" Center "
points=" 0,0 0,26 17,13 "
fill=" Black "/>
</StackPanel>
You need to be able to get the play icon and place it on the button. You can use a combination to actually embed a XAML element inside another XAML element. For example, you can create labels and icons (as the contents of the button) by changing the XAML. Place these elements in the container within the button (here is StackPanel) so that they can be assigned to the Content property of the buttons class, as shown in Figure 2. The resulting button works just like any other button, but it has your own content.
All content in the Figure 2 button
<StackPanel>
<button height= "width=" >
<StackPanel>
<textblock>play </TextBlock>
<polygon points= "0,0 0,26 17,13" fill= "Black"/> </stackpanel>
</Button>
</StackPanel>
It is easy to create such controls using a combination. Unlike the controls in demonstration technologies such as Windows Forms, Visual basic®6.0, and MFC, most composite controls are containers for other controls. When all you really need is a composite control, you don't have to write a custom control.