How do i handle cell double click event on WPF DataGrid, equivalent to windows DataGrid's Events?

后端 未结 3 1965
旧时难觅i
旧时难觅i 2020-12-16 02:08

As you know, in windows C#\'s gridview, if we want to handle a click/double click event on cell then there are events like CellClick, CellDoubleClick, etc.

So, i wan

3条回答
  •  时光取名叫无心
    2020-12-16 02:18

    An alternative way would to be define a DataGridTemplateColumn instead of using the predefined columns like DataGridCheckBoxColumn, DataGridComboBoxColumn and then add an event handler to the UI element defined in the data template.

    Below I have defined a MouseDown event handler for a TextBlock Cell.

    
        
    
            
                
                    
                        
                    
                
            
        
    
    

    In the Code behind file:

    private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
    {
        TextBlock block = sender as TextBlock;
        if (block != null)
        {
            // Some Logic
            // block.Text
        }
    }
    

提交回复
热议问题