Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Firing events programmatically
10 replies. Latest Post by vitya on August 19, 2008.
(0)
vitya
Member
111 points
75 Posts
08-18-2008 1:55 PM |
Hi,
Is there a way to fire control events programmatically? E.g. When the mouse hovers over a button, I want another button to play its MouseEnter animation.
Thanks
Skyrunner
Contributor
2489 points
485 Posts
08-18-2008 2:16 PM |
No, even in C# you can't. But you can call directly the callback and passing the button you want as sender parameter.
08-18-2008 2:52 PM |
Thanks for the quick reply.
That way, though, I cannot start the animation :( or can I?
pbromberg
2088 points
365 Posts
08-18-2008 2:57 PM |
You don't need to put the code logic inside the control's eventhandler body. inside your eventhandler, you can make a call to a separate method. So for example in the mouse hover eventhandler, you can add a call to your method that does the MouseEnter animation. That is, this is what it sounds like you are asking for.
08-18-2008 3:17 PM |
But for the button the animations are defined with VSM. I don't have access to them from outside the button.
What am I missing?
08-18-2008 3:18 PM |
I don't know if its a good practice but you can start the MouseOver animation with this code
yourButton.SetValue(Button.IsMouseOverProperty, true);
Maybe someone else has a bette solution.
08-18-2008 3:47 PM |
Just tried it, but it doesn't seem to fire the MouseEnter event on the other button.
This is the code I use:
btn4.MouseEnter +=
{
}
08-18-2008 3:51 PM |
You said, you wanted the animation starts, and this is what my code does.
When you set the IsMouseOverProperty DP to true, the MouseOver animation defined in the template begins.
Is it what you want?
08-18-2008 4:01 PM |
yes, that's what I want, but it doesn't happen :(
08-18-2008 4:45 PM |
Ok.
In fact it's easy
VisualStateManager.GoToState(button4, "MouseOver", true);
Just call the state you want.
08-19-2008 1:57 AM |
Yes, this was it. Shame on me I didn't think of the simplest solution!
Thank you for your support!