Category: Silverlight

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

Nov 02 2009

Display database data using Silverlight datagrid

First Refer to below link

how to create WCF service and LinqToSQL

Step1: First Create Silverlight Project in VS2008

Step2: In Page.xaml file Drag Silverlight Datagrid control

<data:DataGrid x:Name=”gridRegister“></data:DataGrid>

Step3: Add WCF Service (Register.svc) below link will explain

how to create WCF service and LinqToSQL view this link above

Then add Below OperationContract in Register.svc

Register.svc.cs

[OperationContract]

public IEnumerable<Registration> GetRegisterationList()

{

//SilverlightDataContext is from LinQ to SQL Classes

SilverlightDataContext db = new SilverlightDataContext();

return db.Registrations;

//Registrations is table name in Linq to sql classes

}

Page.Xaml.cs

using SilverlightDB.ServiceReference1; //add this namespace

namespace SilverlightDB

{

public partial class display : UserControl

{

public Page()

{

InitializeComponent();

//RegisterClient is explain in (how to create wcf and linq to sql classes)

RegisterClient client=new RegisterClient();

client.GetRegisterationListCompleted += new EventHandler<GetRegisterationListCompletedEventArgs>(client_GetRegisterationListCompleted);

client.GetRegisterationListAsync();

}

void client_GetRegisterationListCompleted(object sender, GetRegisterationListCompletedEventArgs e)

{

//gridRegister is name of Datagrid in Page.xaml

gridRegister.ItemsSource = e.Result;

}

}

}

Step4: Hit F5 to run the Application.

Alibi3col theme by Themocracy