Search code examples
c#silverlightsilverlight-4.0

How to color textblock on mouse over?


I'm looking to see if there is a way to change the color of a textblock in silverlight on mouse over. I have tried a trigger which I read now doesn't work. I would like to avoid having to do it in the codebehind if at all possible.


Solution

  • Your instinct on not using code behind for that event is a good one. Allow me to sharpen it though: Don't change the visuals from code-behind, but allow your ViewModels/Code-Behind to own the visual state of the control.

    The solution here is to encapsulate the specific visual changes in a custom visual state, and invoke that Visual State either from a ViewModel or a Blend EventTrigger & GoToStateAction.

    To learn more about VisualStateManager I strongly recommend you watch these 4 "How Do I" videos by Steve White @ http://expression.microsoft.com/en-us/cc643423.aspx

    To learn more about the GoToStateBehavior see @ Link