[Original] full analysis code and example of Silverlight DataGrid double-click event analysis, silverlightdatagrid

Source: Internet
Author: User

[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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.