Back to the "Steady Silverlight 3.0 series Article index"
Slow and steady Silverlight (35)-3.0 control Childwindow,savefiledialog,headereditemscontrol,virtualizingstackpanel
Introduced
Silverlight 3.0 Control Overview:
ChildWindow-For a subform that pops up before the parent form
SaveFileDialog-User initiated Save File dialog box (OpenFileDialog-Open File dialog box)
HeaderedItemsControl-controls that render title and collection data
VirtualizingStackPanel-Virtualized StackPanel (that is, only the UI elements that need to be displayed are generated.) Using this control can significantly increase rendering efficiency when a large amount of data is bound and only a small portion of it is displayed at a time.
Online Demo
Http://www.cnblogs.com/webabcd/archive/2009/08/04/1538238.html
Example
1. Demo ChildWindow Application
Childwindowdemo.xaml
<navigation:page x:class= "Silverlight30.Control.ChildWindowDemo"
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 "
xmlns:navigation=" Clr-namespace: System.windows.controls;assembly=system.windows.controls.navigation "
d:designwidth=" 640 "d:DesignHeight=" 480 "
title=" Childwindowdemo Page "
<grid x:name=" LayoutRoot "
<stackpanel>
< Button X:name= "Btnchildwindow" content= "show ChildWindow" click= "Btnchildwindow_click"/>
<button x:Name= " Btncustomchildwindow "content=" show Customchildwindow "click= Btncustomchildwindow_click"/>
< TextBlock x:name= "Lblresult"/>
</stackpanel>
</grid>
</navigation:Page>
ChildWindowDemo.xaml.cs
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;
Using System.Windows.Navigation;
Namespace Silverlight30.control
{
public partial class Childwindowdemo:page
{
Public Childwindowdemo ()
{
InitializeComponent ();
}
private void Btnchildwindow_click (object sender, RoutedEventArgs e)
{
/**//*
* ChildWindow-Subform displayed before the parent form
* Title-sub-form caption
* Content-the contents of the subform
* Hasclosebutton-do you want to have a close button on the subform (x in the upper right corner)?
* Overlaybrush-Brush on the parent form when the subform is open
* Overlayopacity-the opacity of the Brush that is overwritten on the parent form when the subform is opened
* Width-width of the subform
* Height-height of the subform
* Closed Event-Events triggered after the subform is closed
* Show ()-open (display) Subform
*/
ChildWindow child = new ChildWindow ();
Child. title = "caption";
Child. Content = "Contents";
Child. Hasclosebutton = true;
Child. Overlaybrush = new SolidColorBrush (colors.red);
Child. Overlayopacity = 0.3;
Child. Width = 320;
Child. Height = 240;
Child. Show ();
}
void Child_closed (object sender, EventArgs e)
{
/**//*
* Childwindow.dialogresult-Subform passed back to a bool? Value (can be used to describe whether you clicked the OK button or the Cancel button in the subform)
* Childwindow.datacontext-The data context passed back by the subform
*/
Customchildwindow child = sender as Customchildwindow;
MessageBox.Show (String. Format ("dialogresult:{0}; Datacontext:{1} ", child. DialogResult, child. DataContext));
}
private void Btncustomchildwindow_click (object sender, RoutedEventArgs e)
{
Customchildwindow child = new Customchildwindow ();
Child. Closed + = new EventHandler (child_closed);
Child. Show ();
}
}
}