Silverlight Child Window - Passing data between Child and Parent ( Dependency Property ): In this article we are going to see the Child window control in Silverlight .This example is taken from silverlight 4 unleashed and implemented.
Created a Silverlight Project named as SLChildControl .
Add a ChildWindow Control as shown in the fig :

A childWindow Control gets added as shown below :

Add the following code to MyChildWindow.xaml.cs
public const string InputPropertyName = "Input";
public string Input
{
get
{
return (string)GetValue(InputProperty);
}
set
{
SetValue(InputProperty, value);
}
}
public static readonly DependencyProperty InputProperty
= DependencyProperty.Register(
InputPropertyName,typeof(string),typeof(MyChildWindow),new PropertyMetadata("Enter text..."));
Now modify the MainPage.xaml as shown below :
Modify the Code Behind as follows :
private void button1_Click(object sender, RoutedEventArgs e)
{
var window = new MyChildWindow();
window.Closed += new EventHandler(window_Closed);
window.Show();
}
void window_Closed(object sender, EventArgs e)
{
var window = sender as MyChildWindow;
if (window != null && window.DialogResult == true)
{
InputTextBlock.Text = window.Input;
}
}
lets give it a run :

Hit the Button . Child window should open .

Hit OK .

The TextBox in the MainPage gets updated with the text "Enter text .."
How this works is well when you hit the ok or close button on the Child . The child close event is called and it assigns the text to the textbox of the MainPage .
