Note that there are some explanatory texts on larger screens.

plurals
  1. POEventSetters in Theme ResourceDictionary
    text
    copied!<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.eventsetter.aspx" rel="nofollow noreferrer">MSDN says on event setters:</a></p> <blockquote> <p>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.</p> </blockquote> <p>This is confirmed by <a href="https://stackoverflow.com/questions/13562498/wpf-treeview-style-eventsetter-dont-work">the first answer to this SO question</a>, which states:</p> <blockquote> <p>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.</p> </blockquote> <p>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.</p> <p>Adding an event setter to a style in the same resource dictionary, on the other hand, results in an exception.</p> <p>Have I hit a special case where it happens to work?</p> <p>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?</p> <p>My question boils down to:</p> <p><strong>What exactly is meant by MSDN's statement that a theme resource dictionary is <em>often</em> loose binary XAML - how often, under what circumstances exactly?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload