3

Why am I getting this error message? I'm using an event setter!

<Style TargetType="{x:Type xcdg:DataCell}">
    <EventSetter Event="LostFocus" Handler="cellLostFocusHandler" />
</Style>

edit

I'm not using the style inline. It's in a resource, i.e.:

<DataGrid.Resources>
    <Style TargetType="{x:Type xcdg:DataCell}">
        <EventSetter Event="LostFocus" Handler="cellLostFocusHandler" />
    </Style>
</DataGrid.Resources>
Alain
  • 26,663
  • 20
  • 114
  • 184

1 Answers1

8

See this question

It sounds like you're using the Style inline, instead of as a Resource, and there's issues in setting an EventSetter in an inline style

Community
  • 1
  • 1
Rachel
  • 130,264
  • 66
  • 304
  • 490
  • 2
    I'm not - it is in a resource. – Alain Oct 11 '11 at 19:06
  • @Alain Is your DataGrid in a Template, or directly in your Window/UserControl tag? – Rachel Oct 11 '11 at 19:18
  • 1
    It's in a template. The idea here is that I only have to set this event in one place rather than 20 places in my xaml where grids appear. – Alain Oct 11 '11 at 19:22
  • 3
    I've had the same problem occur with EventSetters nested in Templates. Move your Style out of the template and put it directly under Window.Resources or UserControl.Resources, and then reference it via a StaticResource or DynamicResource in your Template. The property should be something like DataGrid.DataGridCellStyle – Rachel Oct 11 '11 at 19:28
  • I see. Well crap, how do I apply that style only to items in that template? I'll make a new question for it. – Alain Oct 11 '11 at 19:32
  • 1
    You should be able to set `` – Rachel Oct 11 '11 at 19:33
  • Couldn't get rid of this error until I removed the Tag - then tadaa... – user947737 Aug 22 '20 at 14:34