I have an element specified inside a style. I need the codebehind to know when IsEnabled changes on one of the elements (the Border in this simplified example), so initially I just set the event like normal:
<UserControl.Resources>
<Style x:Key="TypedValueHelper" TargetType="ContentControl">
<Style.Triggers>
<DataTrigger Binding="{Binding Type, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
Value="Markdown">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border x:Name="BorderThing"
IsEnabledChanged="BorderThing_IsEnabledChanged"/>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
Then Visual Studio complained at me and I remembered that you can't set events directly on an element in a style, so I fixed it:
<UserControl.Resources>
<Style x:Key="BorderThing" TargetType="Border">
<EventSetter Event="IsEnabledChanged" Handler="BorderThing_IsEnabledChanged"/>
</Style>
<Style x:Key="TypedValueHelper" TargetType="ContentControl">
<Style.Triggers>
<DataTrigger Binding="{Binding Type, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
Value="Markdown">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border x:Name="BorderThing"/>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
But now it's telling me The event 'IsEnabledChanged' is not a RoutedEvent ☹
How do I get my event?