If you fed up searching for such an option,here is the solution with 3 simple steps...
- Add a file named generic.xaml.cs
- Right click on themes folder and select new class
- Name it as generic.xaml.cs
partial class generic :ResourceDictionary //This class should inherit from ResourceDictionary
x:Class="MyControls.themes.generic" //The class name should be complete.ie with namespace
Now you can write code for your generic.xaml elements in the generic.xaml.cs file.
The same method can be applied if you want to write code behind for any other xaml resource file.
A sample is attached here