Event setters cannot be used in a style that is contained in a theme resource dictionary. This is because a theme resource dictionary at run time is often loose binary XAML (BAML) files, and does not have any scope defined where accompanying code-behind that defines the handlers can exist.
This is confirmed by the first answer to this SO question, which states:
a resource xaml can't have a code behind file, they are usually called "loose xaml". You can read about that in the msdn about EventSetter.
However, I do not yet understand the limitations to event setters. I have tried using a code-behind file for a resource dictionary. I have assigned an event handler for an event of a control contained within a template defined within a style in said resource dictionary - and it worked.
Adding an event setter to a style in the same resource dictionary, on the other hand, results in an exception.
Have I hit a special case where it happens to work?
Or does setting an event handler in a template always work, but if so, then why can't I use an event setter in a style in the same resource dictionary?
My question boils down to:
What exactly is meant by MSDN's statement that a theme resource dictionary is often loose binary XAML - how often, under what circumstances exactly?