首页 / 软件开发 / Silverlight / 稳扎稳打Silverlight(4) - 2.0控件之DataGrid,DatePicker,Grid……
稳扎稳打Silverlight(4) - 2.0控件之DataGrid,DatePicker,Grid……2010-04-26 cnblogs webabcd稳扎稳打Silverlight(4) - 2.0控件之DataGrid,DatePicker,Grid,GridSplitter,HyperlinkButton,Image在线DEMOhttp://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.csusing 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>