I have been trying to use System.Windows.Interactivity.Interaction with WPF from MS Expression Blend SDK for .NET 4. The problem is that I can't find the Interaction.Triggers attached property there. The Interaction class exists, but I can see only 4 members in it: Equals, GetBehaviors, GetTriggers, ReferenceEquals. I looked at the properties of the reference to System.Windows.Interactivity.dll in my project and found that the path is
"C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries\System.Windows.Interactivity.dll"
So, I opened the file on that path with IL Disassеmbler and found that the Interaction class actually has the Triggers attached property, but the property is declared as private! Then I opened the same dll in \Lib\Desktop directory of Prism SDK and found the same situation there. The versions of these dlls are 2.0.20525.0. There is also a System.Windows.Interactivity.xml file with the System.Windows.Interactivity dlls. In it I found following about TriggersProperty:
This property is not exposed publicly. This forces clients to use the GetTriggers and SetTriggers methods to access the collection, ensuring the collection exists and is set before it is used.
But I didn't find any SetTriggers methods there. BTW, Silverlight's Interaction has TriggersProperty as a public member.
I have seen many examples using Interaction.Triggers with WPF and I assume there shouldn't be any problems. What am I doing wrong?
Well there's definitely something strange going on. Here's what I found:
I don't have an explanation. However, I can say that if you simply write <i:Interaction.Triggers>
in your WPF XAML and reference System.Windows.Interactivity.dll from Prism 4.1, it just works as expected.
I tried checking some other framework classes to see if it's a bug in ILDASM, but those all presented with the correct access modifier. So I don't know why the Prism version works, but it seems to do just that. I haven't tried the straight up Blend SDK version as I've not had a need for it.
edit: A little more info: Digging around with Resharper, I found that Interaction.TriggersProperty is not used anywhere. However, Interaction.GetTriggers is used all over my WPF code. So I'm betting that there's some XAML binding reflection magic that makes this all work. I say "magic" because I don't understand it. Apparently the Blend SDK folks think you should only use the Behaviors and Triggers attached property from XAML, but the Prism folks think you should be able to use it from code as well.