Nov 02 2009

How to Add one XAML file to another XAML file in Silverlight

one-xaml-in-another-xaml

one-xaml-in-another-xaml

In above Figure Silverlight Control name is ExpanderControl.

ExplanderControl contain Themes folder with two xaml files

Generic.xaml

Test.xaml

And By Default it  contain Page.xaml file

Now we are going to open one xaml file in another xaml file i.e generic.xaml file and Test.xaml file will open in Page.xaml file.

Generic.xaml (In themes Folder) file contain below code

<UserControl x:Class=”ExpanderControl.generic

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

Width=”200″ Height=”200″>

<Grid x:Name=”LayoutRoot” Background=”White”>

<Ellipse Fill=”Black” Width=”100″></Ellipse>

</Grid>

</UserControl>

Test.xaml file (In themes Folder) contain below code

<UserControl x:Class=”ExpanderControl.test

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:exp=”clr-namespace:ExpanderControl”

Width=”200″ Height=”200″>

<Grid x:Name=”LayoutRoot” Background=”White”>

<Rectangle Fill=”Blue” ></Rectangle>

</Grid>

</UserControl>

Opening Generic.xaml and Test.xaml file in Page.xaml file

Add this namespace in UserControl   ExpanderControl is Silverlight Control Name

xmlns:exp=”clr-namespace:ExpanderControl”

<UserControl x:Class=”ExpanderControl.Page

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

xmlns:exp=”clr-namespace:ExpanderControl

Width=”400″ Height=”400″>

<Grid x:Name=”LayoutRoot” Background=”White”>

<Grid.RowDefinitions>

<RowDefinition Height=”200″></RowDefinition>

<RowDefinition Height=”200″></RowDefinition>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition Width=”400″></ColumnDefinition>

</Grid.ColumnDefinitions>

<exp:generic Grid.Row=”0″></exp:generic>

<exp:test Grid.Row=”1″></exp:test>

</Grid>

</UserControl>

Run the Application

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Leave a Reply

Alibi3col theme by Themocracy