1
<
common
:
DataGrid
Name
="grdDataGrid"
ItemsSource
="{
Binding
}"
CheckBoxChecked
="grdDataGrid_CheckBoxChecked"
ButtonClick
="grdDataGrid_ButtonClick"
ComboBoxSelectionChanged
="grdDataGrid_ComboBoxSelectionChanged">
2
<
ListView.View
>
3
<
GridView
>
4
<
common
:
DataGridColumn
Header
="First Name"
ColumnType
="TextBlock"
TextBlockTextPath
="LastName"
ButtonValuePath
="ID" />
5
<
common
:
DataGridColumn
Header
="Last Name"
ColumnType
="ComboBox"
ComboBoxTextPath
="LastName"
ComboBoxDisplayMemberPath
="LastName"
ComboBoxSelectedValuePath
="ID"
HasDifferentDataContext
="True"
SortPropertyName
="LastName" />
6
<
common
:
DataGridColumn
Header
="ID"
ColumnType
="CheckBox"
CheckBoxValuePath
="ID"
SortPropertyName
="ID"
Width
="50" />
7
<
common
:
DataGridColumn
Header
="Date of Birth"
TextBlockTextPath
="DateOfBirth"
TextBlockTextAlignment
="Right"
SortPropertyName
="DateOfBirth"
IsDefaultSortColumn
="True" />
8
</
GridView
>
9
</
ListView.View
>
10
</
common
:
DataGrid
>
咱們能夠看到,使用這個控件跟普通的ListView控件沒有太多的區別。咱們只須要在DataGridColumn中指定ColumnType爲Button、CheckBox、ComboBox、TextBox等,默認爲TextBlock,而後對應該類型設定相應的屬性便可。而相關的排序、DataTemplate等功能則已經徹底封裝了。另外,普通的ListView控件的RoutedEventArgs中的信息太少,而取得SourceRowIndex、SourceColumnIndex、CurrentRowIndex、CurrentColumnIndex等則又很難實現,且很是重要,因此筆者也實現了本身的RoutedEventArgs,提供上述各類Index,方便你們在該控件的事件中直接使用。 下面的幾篇文章我將對該控件中的各個重要方面進行一一講解。