flotable Window demo

Wednesday, June 30, 2010

In Silverlight beta Microsoft provide us a Control called Childwindow.


Childwindow it just like we use Midi form in Desktop Windows Application or child form in base form window or you can say that Multiple form in one page but when we use silver-light ChildWindow Control it disable the parent Form. thats mean`s you can not work on parent form before close child-windows and you can not open Multiple child window in parent page to use them like flotable Windows or panels.ChildWindow has to be the top-most element in the Xaml. thats why its always on top and disable all parent controls .silverlight provide us another control for popup its called Popup Control so i just add ChildWindow in Popup as Child and open and close the popup thats i got base and beautiful functionality Childwindow like Floating ,dialog and i can interact with parent form as well or open Multiple childwindows in one form


 



 



<UserControl x:Class="SilverlightFlotingChildWindow.MainPage"



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



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



xmlns:d="http://schemas.microsoft.com/expression/blend/2008"



xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"



mc:Ignorable="d" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"



>



<Canvas x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">



<Button Content="Window 1" Height="23" HorizontalAlignment="Left" Margin="59,270,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />



<Button Content="Window 2" Height="23" HorizontalAlignment="Left" Margin="140,270,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />



<Button Content="Window 3" Height="23" HorizontalAlignment="Left" Margin="221,270,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />


</Canvas>

</UserControl>



 



 



using System;



using System.Collections.Generic;



using System.Linq;



using System.Net;



using System.Windows;



using System.Windows.Controls;



using System.Windows.Documents;



using System.Windows.Input;



using System.Windows.Media;



using System.Windows.Media.Animation;



using System.Windows.Shapes;


namespace SilverlightFlotingChildWindow

{


public partial class MainPage : UserControl

{


public MainPage()

{



InitializeComponent();



}



 


private void button1_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();flotwin.Title = "Blue Window";

 


System.Windows.Controls.Primitives.Popup popup =
new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};



 


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Blue),

Height = 300,



Width = 300



};



flotwin.Closing +=(ss,ee)=>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

 



 



 



LayoutRoot.Children.Add(popup);



}


private void button2_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();

flotwin.Title = "Orange Window";


System.Windows.Controls.Primitives.Popup popup =
new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Orange),

Height = 300,



Width = 300



};



flotwin.Closing += (ss, ee) =>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

LayoutRoot.Children.Add(popup);



}


private void button3_Click(object sender, RoutedEventArgs e)

{


ChildWindow flotwin =
new ChildWindow();

 


flotwin.Title =
"Purple Window";System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();

 



flotwin.MouseLeftButtonDown += (a, x) =>



{


this.LayoutRoot.Children.Remove(popup);

this.LayoutRoot.Children.Add(popup);


popup.IsOpen =
true;

};


flotwin.Content =
new StackPanel()

{


Background =
new SolidColorBrush(Colors.Purple),

Height = 300,



Width = 300



};



flotwin.Closing += (ss, ee) =>



{


popup.IsOpen =
false;

};



popup.Child = flotwin;


popup.IsOpen =
true;

LayoutRoot.Children.Add(popup);



}



}





Download Source Code


share this post
Share to Facebook Share to Twitter Share to Google+ Share to Stumble Upon Share to Evernote Share to Blogger Share to Email Share to Yahoo Messenger More...

2 comments:

Anonymous said...

the text size is so big.. it looks stupid..

Unknown said...

But the content is interesting ! thanks