WPF DataGrid 最全示例程序


程序完整展示如何使用WPF DataGrid,包括绑定到数据集,展示并执行更新,展示Master / Detail视图,在分层应用程序中使用(删除更新插入操作),数据验证(表达式验证,IDataErrorInfo,按绑定的数据集验证),风格设定,列模板,行详细设置等等。

WPF DataGrid Practical Examples

A DataGrid is a user interface component for displaying tabular data to the user, typically providing sorting and editing functionality, among others. DataGrids have been the work-horse of various frameworks such as ASP.NET (GridView) and Windows Forms (DataGridView). However, DataGrids in WPF are rather conspicuous in their absence!

Fortunately, the absence of this control has not hampered the popularity of WPF. The versatility of the ListView control allows very flexible read-only DataGrid functionality. Also, the lack of a DataGrid within the WPF APIs was an excellent opportunity for third party component providers; see Michael Sync's blog for a roundup of the five leading third party WPF DataGrids.

Eventually, in August 2008, Microsoft released its DataGrid CTP (Community Technology Preview - a public beta) to CodePlex to coincide with the release of the .NET Framework 3.5 SP1 and Visual Studio 2008 SP1. The .NET Service Packs provided additional WPF functions including IEditableCollectionView, BindingGroup, and alternating row styles which are all used within the WPF DataGrid. Another small yet very highly welcome feature of SP1 is the Binding.StringFormat which provides a simple mechanism for formatting bound data, as described in this blog post.

More recently, on October 22 2008, DataGrid v1 was released. This is the last update that we will see of the DataGrid before .NET 4.0 is released, and includes new features such as row validation, row details, and design-time support.

Binding to a DataSet

    Displaying Data from a DataSet
    Performing Updates
    Master / Detail View

Binding in a Layered Application

    The Architecture
    Handling Delete Operations
    Handling Updates / Inserts


    Validation on Exceptions
    Validation with IDataErrorInfo
    Validation with Bound DataSets


    Column Templates
    Styling the Validation Error Indicator
    Row Details
    Styling the Column Header
    Having Some Fun ...


App.xaml.cs  Menu.xaml.cs  NorthwindDataSet.cs  NorthwindDataSet.Designer.cs  CustomCellExample.xaml.cs  RowHeaderExample.xaml.cs  StylingExample.xaml.cs  ObjectDataProviders.cs  ValidationByException.xaml.cs  ValidationIDataErrorInfo.xaml.cs  
标签: WPF DataGrid 


用户反馈   关于我们
Copyright (©) ZHIHUISHI.COM 2013 All Rights Reserved.