Triggers RRS feed

  • Question

  • Hi,

    There are some examples on web to show behaviors and use triggers in Silverlight 4 with Blend. Do you know of a link which can introduce to these new features of Silverlight 4 straight with XAML and not using Blend?


    Tuesday, June 22, 2010 1:55 PM


All replies

  •  check this out about half way down:


    Tuesday, June 22, 2010 1:57 PM
  • Thanks that answers my question.

    Can you also advise if I an add a new Routed Event and use this new Routed Event in the trigger?

    Tuesday, June 22, 2010 2:06 PM
  • In code behind? 
    I think you should be able to do something like create a new event trigger in xaml or code behind and add it to the existing triggers for an object. 
    In xaml from object.triggers or in code behind using something like object.Triggers.Add(myTrigger);
    Tuesday, June 22, 2010 2:22 PM
  • There are some examples on web to show behaviors and use triggers in Silverlight 4 with Blend.

    Could you link one of those and show us? There's a terminology question here of whether you mean just the concept of starting an animation or changing an appearance based on a state change (be it property or event), or specifically the FrameworkElement.Triggers property in Silverlight.

    The MSDN article being referenced in a previous post is old. It dates back to before the VisualState model was introduced to Blend and to Silverlight. Visual states are the intended replacement for everything you might think you want to do using FrameworkElement.Triggers. FrameworkElement.Triggers usage is in fact very limited in Silverlight - you can only handle the Silverlight-defined Loaded event, and you can't define true custom routed events in Silverlight. With visual states, you can base your behavior on any state you track as a property value, and you can extend both the (nonrouted) event and state property surface of a custom control and incorporate the extensions into your appearance and visual states. For more information see http://msdn.microsoft.com/en-us/library/cc278068(VS.95).aspx

    Tuesday, June 22, 2010 3:16 PM
  • I will give it a try devdmans. Thanks.

    Wolf Schmidt,

    Thanks for the heads up. I am looking for a state change. I was not sure the Event Triggers were pretty much limited to the Loaded event. Here are the links I found talking about triggers with Blend mostly.


    Can you recommend a link or a sample where we can create new States and change the Visual State through XAML. If I add new states, then I have to use code behind to actually switch the state. This is fine but we would like to avoid it to stick to the MVVM design and we like how in windows presentation foundation all the triggers were embedded at the same place with UI elements.

    Tuesday, June 22, 2010 4:17 PM
  • OK, what you are referring to (or at least the "amazedsaints" URL is referring to) is behaviors. Behaviors also have a concept of triggers, but this is different than the Triggers property that was linked in the second post from devdmans. The Blend/Interactivity trigger concept is more extensible and is not just limited to Loaded event. You don't necessarily need a visual state for behaviors, however there is a dedicated behavior for visual states. Or, for MVVM, you can integrate a command and a behavior. It's actually quite open ended so you might just want to read the introductory material.

    You can find some basic material on Blend behaviors and triggers here: http://msdn.microsoft.com/en-us/library/ff724009(Expression.40).aspx or here http://www.kirupa.com/blend_silverlight/introduction_behaviors_pg1.htm

    More extensive documentation can be found in various blogs: a good roundup is here: http://blogs.msdn.com/b/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx 

    The library that supports behaviors is distributed with Blend itself (it is not part of the Silverlight core, or part of the Silverlight SDK). However, you can get also get the library from the Blend SDK. This makes it possible to open a Blend-created project (with behaviors) without having Blend installed. See this post : http://blogs.msdn.com/b/expression/archive/2009/05/22/expression-blend-and-opening-projects-without-blend-installed.aspx - this is an older post, and references Blend3, but the same concept applies to Blend 4 SDK (see http://msdn.microsoft.com/en-us/library/ff724709(Expression.40).aspx).


    Tuesday, June 22, 2010 6:39 PM
  • Wolf Schmidt, thanks for the links. Appreciate your help.

    Can you suggest if you have any links to creating new custom states in and switch to the new states but not in code behind?

    Tuesday, June 22, 2010 7:03 PM