无法在样式中的Target标记上指定事件'LostFocus'.请改用EventSetter

Ala*_*ain 1 wpf xaml binding .net-3.5

为什么我收到此错误消息?我正在使用事件设定器!

<Style TargetType="{x:Type xcdg:DataCell}">
    <EventSetter Event="LostFocus" Handler="cellLostFocusHandler" />
</Style>
Run Code Online (Sandbox Code Playgroud)

编辑

我没有使用内联样式.它在资源中,即:

<DataGrid.Resources>
    <Style TargetType="{x:Type xcdg:DataCell}">
        <EventSetter Event="LostFocus" Handler="cellLostFocusHandler" />
    </Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)

Rac*_*hel 7

看到这个问题

听起来你使用的是样式内联而不是资源,并且在内联样式中设置EventSetter存在问题

  • 嵌套在模板中的 EventSetter 也出现了同样的问题。将您的样式移出模板并将其直接放在 Window.Resources 或 UserControl.Resources 下,然后通过模板中的 StaticResource 或 DynamicResource 引用它。该属性应该类似于 DataGrid.DataGridCellStyle (3认同)
  • 我不是 - 它属于资源. (2认同)