[源码下载]
稳扎稳打Silverlight(4) - 2.0控件之DataGrID,DatePicker,GrID,GrIDSplitter,Hyperlinkbutton,Image
作者: webabcd
介绍
Silverlight 2.0 控件一览:DataGrID,Image
在线DEMO
http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html
示例
1、DataGrID.xaml
< UserControl xmlns:data ="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data" x:Class ="Silverlight20.Control.DataGrID"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" >
< StackPanel HorizontalAlignment ="left" >
<!--
后台邦定方式,自动生成列
-->
< data:DataGrID x:name ="dGrd" autoGenerateColumns ="True" ></ data:DataGrID >
</ StackPanel >
</ UserControl >
DataGrID.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;
namespace Silverlight20.Control
{
public partial class DataGrID : UserControl
{
public DataGrID()
{
InitializeComponent();
BindData();
}
voID BindData()
{
var source = new Data.sourceData();
// 设置 DataGrID 的数据源
dGrd.ItemsSource = source.GetData().Take(10);
}
}
}
2、DatePicker.xaml
< UserControl x:Class ="Silverlight20.Control.DatePicker"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics ="clr-namespace:System.windows.Controls;assembly=System.windows.Controls" >
< StackPanel HorizontalAlignment ="left" >
<!--
TextBox 结合 Calendar,经典的选择日期的方式
SelectedDateFormat - 被选中的日期的显示格式 [System.windows.Controls.DatePickerFormat枚举]
SelectedDateFormat.Short - 简短格式。默认值。如2008-10-10
SelectedDateFormat.Long - 非简短格式。如2008年10月10日
-->
< basics:DatePicker WIDth ="200" SelectedDateFormat ="Short" ></ basics:DatePicker >
</ StackPanel >
</ UserControl >
3、GrID.xaml
< UserControl x:Class ="Silverlight20.Control.GrID"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
WIDth ="auto" Height ="500" >
<!--
GrID - 表格式布局模式
GrID.RowDeFinitions - 用于定义 GrID 中的行
GrID.ColumnDeFinitions - 用于定义 GrID 中的列
GrID.ShowGrIDlines - 显示网格
GrID.Row - 控件所在的 GrID 的行的索引
GrID.Column - 控件所在的 GrID 的列的索引
GrID.rowspan - 合并行。 控件所在行,以及控件所在行之后的需要连续合并的行的总行数
GrID.ColumnSpan - 合并列。 控件所在列,以及控件所在列之后的需要连续合并的列的总列数
WIDth - 宽度
MinWIDth - 最小宽度
MaxWIDth - 最大宽度
Height - 高度
MinHeight - 最小高度
MaxHeight - 最大高度
WIDth 和 Height 的可用值
auto - 自动设置为一个合适的值。默认值
Pixel - 像素值
* - 比例值。如 * 就是全部,2* & 8* 就是分别占20%和80%
-->
< GrID x:name ="LayoutRoot" Background ="White" ShowGrIDlines ="True" >
< GrID.RowDeFinitions >
< RowDeFinition Height ="50" />
< RowDeFinition Height ="3*" />
< RowDeFinition Height ="7*" />
< RowDeFinition Height ="*" MinHeight ="200" MaxHeight ="500" />
< RowDeFinition Height ="auto" />
</ GrID.RowDeFinitions >
< GrID.ColumnDeFinitions >
< ColumnDeFinition />
< ColumnDeFinition />
< ColumnDeFinition />
</ GrID.ColumnDeFinitions >
< TextBox GrID.Row ="0" GrID.Column ="0" Background ="red" Text ="abc" />
< TextBox GrID.Row ="0" GrID.Column ="1" Background ="red" Text ="abc" GrID.ColumnSpan ="2" HorizontalAlignment ="Center" />
< TextBox GrID.Row ="1" GrID.Column ="0" Background ="red" Text ="abc" />
< TextBox GrID.Row ="1" GrID.Column ="1" Background ="red" Text ="abc" GrID.ColumnSpan ="2" HorizontalAlignment ="Center" />
< TextBox GrID.Row ="2" GrID.Column ="0" Background ="red" Text ="abc" />
< TextBox GrID.Row ="2" GrID.Column ="1" Background ="red" Text ="abc" GrID.rowspan ="2" VerticalAlignment ="Bottom" />
< TextBox GrID.Row ="2" GrID.Column ="2" Background ="red" Text ="abc" />
< TextBox GrID.Row ="3" GrID.Column ="2" Background ="red" Text ="abc" />
< TextBox GrID.Row ="4" GrID.Column ="2" Background ="red" Text ="abc" />
</ GrID >
</ UserControl >
4、GrIDSplitter.xaml
< UserControl x:Class ="Silverlight20.Control.GrIDSplitter"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics ="clr-namespace:System.windows.Controls;assembly=System.windows.Controls" >
< GrID x:name ="LayoutRoot" Background ="White" >
< GrID.RowDeFinitions >
< RowDeFinition Height ="100" />
< RowDeFinition Height ="5" />
< RowDeFinition Height ="100" />
</ GrID.RowDeFinitions >
< GrID.ColumnDeFinitions >
< ColumnDeFinition WIDth ="100" />
< ColumnDeFinition WIDth ="5" />
< ColumnDeFinition WIDth ="100" />
</ GrID.ColumnDeFinitions >
< Rectangle GrID.Row ="0" GrID.Column ="0" Fill ="Red" />
< Rectangle GrID.Row ="0" GrID.Column ="2" Fill ="Green" />
< Rectangle GrID.Row ="2" GrID.Column ="0" Fill ="Blue" />
< Rectangle GrID.Row ="2" GrID.Column ="2" Fill ="Yellow" />
<!--
ShowsPrevIEw - 拖动 GrIDSplitter 时,是要即时显示拖动结果(false 默认值),还是要先预览GrIDSplitter被拖动的位置(true)
-->
< basics:GrIDSplitter GrID.Row ="1" GrID.Column ="0" GrID.ColumnSpan ="3" ShowsPrevIEw ="True" HorizontalAlignment ="Stretch" VerticalAlignment ="Stretch" />
< basics:GrIDSplitter GrID.Row ="0" GrID.Column ="1" GrID.rowspan ="3" HorizontalAlignment ="Stretch" VerticalAlignment ="Stretch" />
</ GrID >
</ UserControl >
5、Hyperlinkbutton.xaml
< UserControl x:Class ="Silverlight20.Control.Hyperlinkbutton"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" >
< StackPanel HorizontalAlignment ="left" >
<!--
NavigateUri - 超级链接的目标地址
Targetname - 目标名
-->
< Hyperlinkbutton Content ="http://webabcd.cnblogs.com" NavigateUri ="http://webabcd.cnblogs.com/" HorizontalContentAlignment ="Center" Targetname ="_blank" Background ="Black" Foreground ="White" margin ="5" WIDth ="200" />
<!--
Hyperlinkbutton.Content - 超级链接所显示的内容
-->
< Hyperlinkbutton NavigateUri ="http://webabcd.cnblogs.com/" Targetname ="_blank" margin ="5" WIDth ="200" >
< Hyperlinkbutton.Content >
< Image Source ="/Silverlight20;component/Images/logo.jpg" />
</ Hyperlinkbutton.Content >
</ Hyperlinkbutton >
</ StackPanel >
</ UserControl >
6、Image.xaml
< UserControl x:Class ="Silverlight20.Control.Image"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" >
< StackPanel HorizontalAlignment ="left" >
<!--
Source - 程序目录下的图片文件地址
-->
< Image Source ="/logo.jpg" margin ="5" WIDth ="100" />
<!--
Source - 程序集内的图片文件地址 [/程序集名;component/图片路径]
-->
< Image Source ="/Silverlight20;component/Images/logo.jpg" margin ="5" WIDth ="200" />
<!--
Source - 互联网的图片文件地址
-->
< Image Source ="http://silverlight.net/themes/silverlight/images/logo.jpg" margin ="5" WIDth ="100" />
<!--
Source - 后台方式设置Image的Source
-->
< Image x:name ="img" margin ="5" WIDth ="100" />
< Image x:name ="img2" margin ="5" WIDth ="100" />
</ StackPanel >
</ UserControl >
Image.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.Media.Imaging;
using System.windows.Resources;
namespace Silverlight20.Control
{
public partial class Image : UserControl
{
public Image()
{
InitializeComponent();
// 后台方式设置Image的Source
img.source = new BitmAPImage(new Uri("/Silverlight20;component/Images/logo.jpg", UriKind.relative));
StreamResourceInfo sri = Application.GetResourceStream(
new Uri("/Silverlight20;component/Images/logo.jpg", UriKind.relative));
BitmAPImage imageSource = new BitmAPImage();
imageSource.SetSource(sri.Stream);
img2.source = imageSource;
}
}
}
OK
[源码下载] 总结
以上是内存溢出为你收集整理的稳扎稳打Silverlight(4) - 2.0控件之DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image全部内容,希望文章能够帮你解决稳扎稳打Silverlight(4) - 2.0控件之DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)