[索引页]
@L_502_1@
作者:webabcd
介绍
Silverlight 3.0 控件一览:
在线DEMO
http://www.voidcn.com/article/p-boakcggz-tq.html
示例
1、演示 ChildWindow 的应用
ChildWindowDemo.xaml
@L_502_1@
稳扎稳打Silverlight(35) - 3.0控件之ChildWindow,SaveFileDialog,HeaderedItemsControl,VirtualizingStackPanel
作者:webabcd
介绍
Silverlight 3.0 控件一览:
- ChildWindow - 用于在父窗体前弹出一个的子窗体
- SaveFileDialog - 用户发起的保存文件对话框(OpenFileDialog - 打开文件对话框)
- HeaderedItemsControl - 呈现标题和集合数据的控件
- VirtualizingStackPanel - 虚拟化的 StackPanel(即仅生成需要显示的 UI 元素。当绑定了大量数据,而某时仅显示其中一小部分的时候,使用此控件则可大幅提高呈现效率)
在线DEMO
http://www.voidcn.com/article/p-boakcggz-tq.html
示例
1、演示 ChildWindow 的应用
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>
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
CustomChildWindow.xaml(自定义子窗体)
<controls:ChildWindow x:Class="Silverlight30.Control.CustomChildWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="320" Height="240"
Title="我是标题">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDeFinitions>
<RowDeFinition />
<RowDeFinition Height="Auto" />
</Grid.RowDeFinitions>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0" Grid.Row="1" />
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,79,0" Grid.Row="1" />
</Grid>
</controls:ChildWindow>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="320" Height="240"
Title="我是标题">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDeFinitions>
<RowDeFinition />
<RowDeFinition Height="Auto" />
</Grid.RowDeFinitions>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0" Grid.Row="1" />
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,79,0" Grid.Row="1" />
</Grid>
</controls:ChildWindow>
CustomChildWindow.xaml.cs
2、SaveFileDialog 和 OpenFileDialog 的演示
SaveFileDialogDemo.xaml
SaveFileDialogDemo.xaml
<navigation:Page x:Class="Silverlight30.Control.SaveFileDialogDemo"
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="SaveFileDialog Page">
<Grid x:Name="LayoutRoot">
<StackPanel>
<TextBox x:Name="txtInfo" />
<Button x:Name="btnSave" Content="保存" Click="btnSave_Click" />
<Button x:Name="btnLoad" Content="载入" Click="btnLoad_Click" />
</StackPanel>
</Grid>
</navigation:Page>
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="SaveFileDialog Page">
<Grid x:Name="LayoutRoot">
<StackPanel>
<TextBox x:Name="txtInfo" />
<Button x:Name="btnSave" Content="保存" Click="btnSave_Click" />
<Button x:Name="btnLoad" Content="载入" Click="btnLoad_Click" />
</StackPanel>
</Grid>
</navigation:Page>
SaveFileDialogDemo.xaml.cs
3、演示 HeaderedItemsControl 的使用
HeaderedItemsControl.xaml
HeaderedItemsControl.xaml
<navigation:Page xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="Silverlight30.Control.HeaderedItemsControl"
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="HeaderedItemsControl Page">
<Grid x:Name="LayoutRoot">
<!--
HeaderedItemsControl - 呈现标题和集合数据的控件
HeaderedItemsControl.Header,HeaderedItemsControl.HeaderTemplate - 用于显示标题
HeaderedItemsControl.Items,HeaderedItemsControl.ItemTemplate - 用于显示集合数据
-->
<controls:HeaderedItemsControl x:Name="headeredItemsControl" >
<controls:HeaderedItemsControl.Header>
<TextBlock Text="Header" />
</controls:HeaderedItemsControl.Header>
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
</Grid>
</navigation:Page>
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="HeaderedItemsControl Page">
<Grid x:Name="LayoutRoot">
<!--
HeaderedItemsControl - 呈现标题和集合数据的控件
HeaderedItemsControl.Header,HeaderedItemsControl.HeaderTemplate - 用于显示标题
HeaderedItemsControl.Items,HeaderedItemsControl.ItemTemplate - 用于显示集合数据
-->
<controls:HeaderedItemsControl x:Name="headeredItemsControl" >
<controls:HeaderedItemsControl.Header>
<TextBlock Text="Header" />
</controls:HeaderedItemsControl.Header>
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
</Grid>
</navigation:Page>
HeaderedItemsControl.xaml.cs
4、演示 VirtualizingStackPanel 的应用
VirtualizingStackPanel.xaml
VirtualizingStackPanel.xaml
<navigation:Page x:Class="Silverlight30.Control.VirtualizingStackPanel"
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="VirtualizingStackPanel Page">
<Grid x:Name="LayoutRoot">
<ListBox x:Name="listBox" VerticalAlignment="Top" HorizontalAlignment="Left"
Height="50" Width="300">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<!--
VirtualizingStackPanel - 虚拟化的 StackPanel(即仅生成需要显示的 UI 元素。当绑定了大量数据,而某时仅显示其中一小部分的时候,使用此控件则可大幅提高呈现效率)
Orientation - 数据的排列方式(垂直排列或水平排列)
-->
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</navigation:Page>
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="VirtualizingStackPanel Page">
<Grid x:Name="LayoutRoot">
<ListBox x:Name="listBox" VerticalAlignment="Top" HorizontalAlignment="Left"
Height="50" Width="300">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<!--
VirtualizingStackPanel - 虚拟化的 StackPanel(即仅生成需要显示的 UI 元素。当绑定了大量数据,而某时仅显示其中一小部分的时候,使用此控件则可大幅提高呈现效率)
Orientation - 数据的排列方式(垂直排列或水平排列)
-->
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</navigation:Page>
VirtualizingStackPanel.xaml.cs
OK
[源码下载]
[源码下载]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。