How to remove "DataGridCheckBoxColumn" highlighting when cell is focused #19437
-
I have a DataGrid that I'm using to display various items, one of the columns is a checkbox, and the other is just a normal textbox. The checkbox column highlights the selected cell's checkbox when given focus, and I'd prefer that it didn't. This highlighting also causes issues when a user reorders selected items using a separate button. Here's an image of what's going on after reordering the selected item down: https://i.imgur.com/n1hGRBp.png. I'm also using the default Fluent themes for both the application and the DataGrid. Here's the XAML for the DataGrid: <DataGrid Name="ModListView" Margin="20, 0, 20, 20" Background="#FF4B4B4B" ItemsSource="{Binding ModList}" SelectionChanged="ModList_OnSelectionChanged">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Enabled" Width="*" Binding="{Binding Enabled}" CanUserSort="False" />
<DataGridTextColumn Header="Mod Name" Width="2*" Binding="{Binding Name}" CanUserSort="False" IsReadOnly="True" Foreground="White" />
</DataGrid.Columns>
</DataGrid> Here's the code for how I'm shifting selected items down the list: private void ModDown_OnClick(object sender, RoutedEventArgs e) {
var viewModel = DataContext as MainWindowViewModel;
var selection = ModListView.SelectedItems.Cast<ModInfo>().OrderBy(m => viewModel!.ModList.IndexOf(m)).ToList();
if (viewModel == null) return;
var limit = viewModel.ModList.Count - 1;
foreach (var i in selection.Select(m => viewModel.ModList.IndexOf(m)).OrderByDescending(x => x)) {
if (i < limit) {
(viewModel.ModList[i + 1], viewModel.ModList[i]) = (viewModel.ModList[i], viewModel.ModList[i + 1]);
} else {
--limit;
}
}
// Restore selection
foreach (var mod in selection) {
ModListView.SelectedItems.Add(mod);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I prefer to use DataGridTemplateColumns instead of CheckBoxColumn because it gives me much more freedom about representation and behavior. |
Beta Was this translation helpful? Give feedback.
I prefer to use DataGridTemplateColumns instead of CheckBoxColumn because it gives me much more freedom about representation and behavior.