How to make DataGrid Row really fully selectable (clicking on non-cell area)
- by Samuel
The question might be a little misleading.
Here is a screenshot of a DataGrid that has some dummy values (code provided below)
Is there a way to make the white area not covered by a cell clickable? My intention: I want to have full row selection. This can be achieved by SelectionUnit="FullRow" which is fine but how can I make the white area implicitly select the entire row without expanding available cells in width and avoiding code behind
Here is the repro code:
Xaml:
<Window x:Class="DGVRowSelectTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<DataGrid ItemsSource="{Binding Names}" SelectionMode="Single" SelectionUnit="FullRow" >
</DataGrid>
</Window>
Dummy Code behind of it (just sets the two entries up)
using System.Collections.Generic;
using System.Windows;
namespace DGVRowSelectTest
{
public partial class MainWindow : Window
{
private IList<KeyValuePair<string, string>> _names = new List<KeyValuePair<string, string>>{new KeyValuePair<string, string>("A1", "A2"),new KeyValuePair<string, string>("B1","B2")};
public IList<KeyValuePair<string, string>> Names{get { return _names; }set { _names = value; }}
public MainWindow()
{
InitializeComponent();
}
}
}