I have restyled a DataGrid and it got rather complex so I moved the styles (DataGrid, DataGridCell, DataGridRow,...) to a ResourceDictionary. I gave all of them a x:Key and referenced them e.g. as DataGrid.RowStyle="{StaticResource SuperRowStyle}". Now I want to use an EventSetter on the Row as well, but obviously I can't set it in the ResourceDictionary, but I can't set it in the Window as well, since it gets overridden by the RowStyle property. How can I do this? BR, Daniel
Asked
Active
Viewed 430 times
2 Answers
1
I'll answer it myself as a good solution is provided in the comments. I create a style in the window where I need the EventSetter and use BasedOn with the needed style.

Daniel
- 597
- 11
- 19
-
Geeez, makes total sense. I've been struggling for a couple of hours on this. – Nick Pearce May 02 '19 at 22:34
0
Now I want to use an
EventSetter
on the Row as well, but obviously I can't set it in theResourceDictionary
..
Yes, you can provided that you add a code-behind file to the ResourceDictionary
:
Is it possible to set code behind a resource dictionary in WPF for event handling?
The handler must be defined in the same class as the EventSetter
.

mm8
- 163,881
- 10
- 57
- 88
-
I saw that, but I expected to be able to use the Window class for the EventHandler. That is not working however. – Daniel Apr 13 '18 at 06:24
-
No. As I mentioned, you *cannot* define the EventSetter in one class and the event handler in another. This won't work. But there should be no reason do to this anyway. You could call any method you want in the event handler. – mm8 Apr 13 '18 at 13:43