Posted by: Zeeshan Amjad | August 15, 2009

Creating Nested Control Using XAML


Creating a nested control in XAML is very easy. You can simply use the content property of any control to placed one more control. It is similar to put control inside the window. If we want to put more than one control inside the control, then we will use some layout such as stack panel, wrap panel, grid etc. Here is a simple XAML code to create a nested button.

  1: <Window x:Class="wpf6.Window1"
  2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:     Title="Nested Control" Name="winMain"  Height="300" Width="300">
  5:     <StackPanel>
  6:         <Button Width="200" Height="100" Margin="5,5"  >  
  7:             <Button.Effect>
  8:                 <DropShadowEffect/>
  9:             </Button.Effect>
 10:             <StackPanel>
 11:                 <Button Width="50" Margin="5" Height="35" Grid.Column="0" Grid.Row="1" >
 12:                     <Button.Effect>
 13:                         <DropShadowEffect/>
 14:                     </Button.Effect>
 15:                     Inner 1
 16:                 </Button>
 17: 
 18:                 <Button Width="50" Margin="5" Height="35" Grid.Column="0" Grid.Row="1" >
 19:                     <Button.Effect>
 20:                         <DropShadowEffect/>
 21:                     </Button.Effect>
 22:                     Inner 2
 23:                 </Button>
 24:             </StackPanel>
 25:         </Button>
 26:     </StackPanel>
 27: </Window>
 28: 

And here is the output of this program.

NestedControl

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: