[WPF C#] Change Cell background color in DataGrid when selected

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to see how we can set custom background color for selected cells in data grid as you can see we have a data grid here and the item source is a very simple list of authors and this is the outer let's see how it looks like and if we select the cells so the the selection color the selected color is the default color that WPF has so we basically want to change that so for that we need to change the the data grid style here so we're gonna say data grid cell Style so we want we basically want to change the cell Style and then we are going to use triggers so we want to say if the data grid cell is selected then change the background color so our trigger property is going to be data grid cell is selected and when value is true what we what we want to do is we want to set data grid cell background to any custom color for example let's do red okay that should be it let's let's try yeah that worked you might you might also want to not set the style directly in data grid but rather create a resource for that so basically we can have in those resources and uh and move everything there so for that we can have so we basically gonna remove everything here and uh so here we need to have Target type uh X Type we're gonna say data grid cell this worked too but please note that this is going to override all data grid cells that you might have in your project which which is not always uh what you want to do so if that's not the case if that's not what you want to achieve you can also add a key here let's say myself Style and now you need to specify for your particular data grade that you want to use this particular style so for that we can say cell style equals to static resource my sales tag that worked that's all thanks for listening
Info
Channel: HowToCode
Views: 11
Rating: undefined out of 5
Keywords:
Id: N5VX6ZIMsWc
Channel Id: undefined
Length: 4min 3sec (243 seconds)
Published: Wed Sep 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.