[Original] full analysis code and example of Silverlight DataGrid double-click event analysis, silverlightdatagrid
Silverlight is used in the company's projects, and there are few technical materials for silverlight. So I will share it with you for your reference.
The code for the DataGrid double-click event in Silverlight is as follows:
1. In the front-end xaml file, you need to add event binding to the properties of the datagrid.
“MouseLeftButtonUp="dataGrid_MouseLeftButtonUp”
<Sdk: DataGrid Grid. Row = "1" Name = "dataGrid1" AutoGenerateColumns = "False" IsReadOnly = "True" ColumnWidth = "*" ItemsSource = "{Binding SearchResult }"MouseLeftButtonUp = "maid"CopyingRowClipboardContent = "Maid CopyingRowClipboardContent"> <sdk: DataGrid. columns> <sdk: Maid Header = "consulting No." Binding = "{Binding Code}"/> </sdk: DataGrid. columns> </sdk: DataGrid>
2. In the background xaml. cs file, you need to define several variables in advance to record the pre-click time and so on.
DateTime lastClickTime = DateTime.Now; object lastClickItem; public delegate void DataItemEventHandler(object sender, DataItemDoubleClickArgs fe); public event DataItemEventHandler DataItemDoubleClick;
3. Write the corresponding event in the background xaml. cs file.
/// <Summary> /// double-click the mouse to select the DataGridItem effect. /// </summary> /// <param name = "sender"> </param> // <param name = "e"> </param> void dataGrid_MouseLeftButtonUp (object sender, mouseButtonEventArgs e) {var eventSource = e. originalSource; var now = DateTime. now; var ts = now. subtract (lastClickTime); var diff = ts. totalMilliseconds; lastClickTime = now; // if the time difference between the two double-click operations is less than ms and the same project is clicked, the event var nowClickItem = dataGrid1 is triggered.. SelectedItem; if (diff <250 & lastClickItem = nowClickItem) {// throw the datagrid double-click event OnDataItemDoubleClick (nowClickItem, new DataItemDoubleClickArgs (eventSource);} lastClickItem = nowClickItem ;} // double-click protected virtual void OnDataItemDoubleClick (object sender, DataItemDoubleClickArgs e) {if (DataItemDoubleClick! = Null) DataItemDoubleClick (sender, e );}
4. After the debugging is completed, the debugging result is OK.