The higher level controls in WPF are composed by smaller pieces. One such example is that there is a RepeatButton, which keeps on firing the Click event as long as the button is pushed down. This is used by scrollbars for example.
Many of the controls has a Content property. The interesting thing is that it is possible to put various things in the Content. It could be a simple string, but just as well it could be more XAML code. I have created two small samples just to show this off. The first example is a combo box with two items added. The items is not just a simple string, but rather XAML code.
The pictures are created on a Windows 2003 Server and therefore the "old" theme.The picture above is created by the following XAML:
<ComboBox Height="26" Margin="120,108,143,0" Name="comboBox1" VerticalAlignment="Top">
<StackPanel Width="150">
<TextBlock FontSize="14" FontWeight="Bold">Caption 1</TextBlock>
<TextBlock TextWrapping="Wrap">The description of the item with Caption 1.</TextBlock>
</StackPanel>
<StackPanel Width="150">
<TextBlock FontSize="14" FontWeight="Bold">Caption 2</TextBlock>
<TextBlock TextWrapping="Wrap">The description of the item with Caption 2.</TextBlock>
</StackPanel>
</ComboBox>
Note that the Items property is like a old VB6 default property, and I therefore do not need to type it. I have created tow StackPanels (one for each item) and simply added two blocks of text. There could just as well have been images and other WPF elements. I guess that it would not be too difficult to create a combo box with "columns", a common requirement and often a reason to buy third party products.
I have also created a second example showing a tooltip.
The tooltip is created by the following XAML code (note that this is almost the first WPF XAML I written so there are probably better ways to solve this):
<TextBox Height="26" Margin="120,0,143,111" Name="textBox1" VerticalAlignment="Bottom">
2003
<TextBox.ToolTip>
<Grid>
<Image Margin="3,3,0,0" Source="C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2005ImageLibrary\icons\Misc\eventlogError.ico" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel Margin="20,0,0,0">
<Label FontWeight="Bold">Invalid value</Label>
<TextBlock>The provided value is incorrect.</TextBlock>
</StackPanel>
</Grid>
</TextBox.ToolTip>
</TextBox>
In this post I have showed some of the composability features of WPF that I find very interesting and nice. This brings a lot of power and possibilities without relying on third party controls.