【正文】
t=Left Margin=18,231,0,71 Width=302/ data:DataGrid x:Name=dgEmployee Height=188 HorizontalAlignment=Left Margin=18,19,0,0 VerticalAlignment=Top Width=302/ Grid x:Name=LayoutRoot Background=White Width=640 Height=480 Width=640 Height=480 assembly= x:Class= 效果圖: = em。 (new Employees(2, 李四, 24))。 ()。...{ void MainPage_Loaded(object sender, RoutedEventArgs e) } InitializeComponent()。...{ public MainPage() EmployeeAge = employeeage。 EmployeeID = employeeid。...{ public Employees(int employeeid, string employeename, int employeeage) ...{ } public Employees() } public int EmployeeAge ...{ get。 } public string EmployeeName ...{ get。 } public int EmployeeID ...{ get。...{ public class Employees //定義數(shù)據(jù)類 namespace SilverlightClient ...{ using 。 using 。 using 。 using 。 using 。mc:Ignorable=d xmlns:data=clrnamespace:。xmlns:d= xmlns:mc= xmlns:x= xmlns= } }2)使用業(yè)務(wù)對象效果圖::UserControl } string[] sp = ...{ }。 += new RoutedEventHandler(MainPage_Loaded)。 using 。 using 。 using 。 using 。 using 。/Grid /UserControlusing ...System。data:DataGrid x:Name=dgEmployee Height=188 HorizontalAlignment=Left Margin=18,19,0,0 VerticalAlignment=Top Width=302/ Grid x:Name=LayoutRoot Background=White Width=640 Height=480 Width=640 Height=480 assembly= x:Class= 前者一般用于普通數(shù)據(jù)綁定,而后者則常用于進行數(shù)據(jù)的雙向綁定來保證數(shù)據(jù)的同步性。SelectionChanged:發(fā)生于當SelectedItem或SelectedItems屬性值改變時。CurrentCellChanged:發(fā)生于一個單元格成為當前單元格時。CellEditEnded:發(fā)生于一個單元格編輯已被確認或取消。VerticalScrollBarVisibility:獲取或設(shè)置垂直滾動條的顯示樣式。SelectionMode:獲取或設(shè)置DataGrid的選取模式。SelectedItem:獲取或設(shè)置與當前被選中行綁定的數(shù)據(jù)項。RowStyle:獲取或設(shè)置呈現(xiàn)行時的樣式。RowHeaderWidth:獲取或設(shè)置行頭的寬度。RowGroupHeaderStyles:獲取呈現(xiàn)行分組頭部的樣式。RowDetailsTemplate:獲取或設(shè)置被用于顯示行詳細部分的內(nèi)容的模板。MinColumnWidth:獲取或設(shè)置DataGrid的最小列寬。IsReadOnly:獲取或設(shè)置DataGrid是否為只讀。HorizontalGridLinesBrush:獲取或設(shè)置水平網(wǎng)格線的筆刷。GridLinesVisibility:獲取或設(shè)置網(wǎng)格線的顯示形式。DropLocationIndicatorStyle:獲取或設(shè)置呈現(xiàn)列頭時的樣式。CurrentItem:獲取包含當前單元格且與行綁定的數(shù)據(jù)項。ColumnWidth:獲取或設(shè)置列寬。ColumnHeaderStyle:獲取或設(shè)置列頭的樣式。CellStyle:獲取或設(shè)置單元格的樣式。CanUserReorderColumns:獲取或設(shè)置一個值用來判斷是否允許用戶重新排列表列的位置。AreRowGroupHeadersFrozen:獲取或設(shè)置一個值用來判斷是否凍結(jié)分組行的頭部。組件常用屬性:AlternatingRowBackground:獲取或設(shè)置一個筆刷用來描繪DataGrid奇數(shù)行的背景。GetGroupFromItem:從具體Item中得到分組。CommitEdit:確認DataGrid的編輯完成。CancelEdit:取消DataGrid的編輯狀態(tài)。本文先介紹該組件的基本特性,接著通過幾個簡單實例來說明該組件的基本數(shù)據(jù)操作過程。Silverlight強大的DataGrid組件[1]說明:DataGrid組件是Silverlight數(shù)據(jù)組件中最為常用并且是功能最為強大的數(shù)據(jù)組件。因此,對開發(fā)者而言,深入了解其特性是十分有必要的。組件所在命名空間:組件常用方法:BeginEdit:使DataGrid進入編輯狀態(tài)。CollapseRowGroup:閉合DataGrid的行分組。ExpandRowGroup:展開DataGrid的行分組。ScrollIntoView:滾動DataGrid視圖。AreRowDetailsFrozen:獲取或設(shè)置一個值用來判斷是否凍結(jié)每行內(nèi)容的詳細信息。AutoGenerateColumns:獲取或設(shè)置一個值用來判斷是否允許自動生成表列。CanUserSortColumns:獲取或設(shè)置一個值用來判斷是否允許用戶按列對表中內(nèi)容進行排序。ColumnHeaderHeight:獲取或設(shè)置列頭的高度。Columns:獲取組件中包含所有列的集合。CurrentColumn:獲取或設(shè)置包含當前單元格的列。DragIndicatorStyle:獲取或設(shè)置當拖曳列頭時的樣式。FrozenColumnCount:獲取或設(shè)置凍結(jié)列的個數(shù)。HeadersVisibility:獲取或設(shè)置行頭及列頭的顯示形式。HorizontalScrollBarVisibility:獲取或設(shè)置水平滾動條的顯示樣式。MaxColumnWidth:獲取或設(shè)置DataGrid的最大列寬。RowBackground:獲取或設(shè)置用于填充行背景的筆刷。RowDetailsVisibilityMode:獲取或設(shè)置一個值用以判定行詳細部分是否顯示。RowHeaderStyle:獲取或設(shè)置呈現(xiàn)行頭的樣式。RowHeight:獲取或設(shè)置每行的高度。SelectedIndex:獲取或設(shè)置當前選中部分的索引值。SelectedItems:獲取與當前被選中的各行綁定的數(shù)據(jù)項們的列表(List)。VerticalGridLinesBrush:獲取或設(shè)置垂直網(wǎng)格線的筆刷。組件常用事件:BeginningEdit:發(fā)生于一個單元格或行進入編輯模式之前。CellEditEnding:發(fā)生于一個單元格正在結(jié)束編輯時。PreparingCellForEdit:發(fā)生于在DataGridTemplateColumn下的單元格進入編輯模式時。實例:為DataGrid提供數(shù)據(jù)源的常用類型主要有兩類:List和ObservableCollection。下面就分別給出這兩種DataProvider的例子:①List1)最簡單的綁定效果圖::UserControl xmlns= xmlns:x= xmlns:d= xmlns:mc= mc:Ignorable=d xmlns:data=clrnamespace:。 using 。 using 。 using 。 using 。 using 。 namespace SilverlightClient ...{ public partial class MainPage : UserControl ...{ public MainPage() ...{ InitializeComponent()。 } void MainPage_Loaded(object sender, RoutedEventArgs e) ...{ string dataSource = H e l l o !。 = (sp, ).ToList()。assembly= x:Class= Width=640 Height=480 Grid x:Name=LayoutRoot Background=White Width=640 Height=480 data:DataGrid x:Name=dgEmployee Height=188 HorizontalAlignment=Left Margin=18,19,0,0 VerticalAlignment=Top Width=302/ /Grid /UserControl:using ...System。 using 。 using 。 using 。 using 。 using 。 set。 set。 set。 EmployeeName = employeename。 } } public partial class MainPage : UserControl ...{ List em = new List()。 += new RoutedEventHandler(MainPage_Loaded)。 (new Employees(1, 張三, 23))。 (new Employees(3, 王五, 25))。 } } }②ObservableCollection注:要實現(xiàn)數(shù)據(jù)同步的雙向綁定,則業(yè)務(wù)對象一定要實現(xiàn)INotifyPropertyChanged接口。:UserControl xmlns= xmlns:x= xmlns:d= xmlns:mc= mc:Ignorable=d xmlns:data=clrnamespace:。 using 。 using 。 using 。 using 。 using 。 using 。 namespace SilverlightClient ...{ public class Employees : INotifyPropertyChanged ...{ private string name。 } set...{ if( value != name) ...