Silverlight: why do we havetriggers? or, why do we have them and they simply refuse to work?
After installing the Silverlight templates, I've started learning it by trying to build a new button control (the choice may seem strange, but currently Silverlight doesn't have any controls). Well, if you create a new project based on the template, you'll see that it already has code that reproduces the basic behavior of a button. After looking at the code, I thought that most of the button's behavior could be built directly from XAML (at least, that's what i thought then). Let me explain this a little better: the default code generated by the project template has javascript code for handling the mouse enter/leave events which changes the offset of a linear gradient brush that is applied to fill the interior of the rectangle. Oh these MS guys...why, oh why did they write that js code when you have routed events and triggers??? So, with this basic WPF knowledge, I decided to remove the js references and add two triggers: onde for the Rectangle.MouseEnter event and another for the Rectangle.MouseLeave event. Each has its own storyboard, where a single DoubleAnimation refreshes the Offset values of one of the gradients (ie, it simply mimics the js default code, but it uses animations inside storyboards which respond to events -or, at least that's what i thought it would do).
guess what: it simply didn't work. I tried replacing the events for mouse down/up and again it didn't work. In fact, i simply couldn't see anything! It was only when i changed the duration of the animation that i was able to see what's going on: the animations were being run in sequence, during the loading of the controls! Yes, that's right: even though I've set the events to enter/leave and mouse up/down, the damn thing only worked during the loaded event (at least, that's what it seemed)...
After reading the docs, I've finally found something similar here. I've copied/pasted it and guess what? It doesn't work! Interestingly, if you adapt it and put it in xaml pad, it works as expected (so does my initial button code)
Now, the big question: why doesn't it work? aren't we suppose to have routed events? or am I doing something wrong?
anyone?
thanks!