Single click edit in WPF DataGrid

前端 未结 11 1559
野的像风
野的像风 2020-11-27 10:47

I want the user to be able to put the cell into editing mode and highlight the row the cell is contained in with a single click. By default, this is double click.

H

11条回答
  •  失恋的感觉
    2020-11-27 11:14

    The solution from http://wpf.codeplex.com/wikipage?title=Single-Click%20Editing worked great for me, but I enabled it for every DataGrid using a Style defined in a ResourceDictionary. To use handlers in resource dictionaries you need to add a code-behind file to it. Here's how you do it:

    This is a DataGridStyles.xaml Resource Dictionary:

        
            
                    
                
            
        
    
    

    Note the x:Class attribute in the root element. Create a class file. In this example it'd be DataGridStyles.xaml.cs. Put this code inside:

    using System.Windows.Controls;
    using System.Windows;
    using System.Windows.Input;
    
    namespace YourNamespace
    {
        partial class DataGridStyles : ResourceDictionary
        {
    
            public DataGridStyles()
            {
              InitializeComponent();
            }
    
         // The code from the myermian's answer goes here.
    }
    

提交回复
热议问题