How can I Have a WPF EventTrigger on a View trigger when the underlying Viewmodel dictates it should?

后端 未结 4 1714
小蘑菇
小蘑菇 2020-11-29 04:37

Here\'s the scenario:

I have the following user control, the idea is that it\'s view model should be able to signal to the view that it needs to \"Activate the Glow\

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 05:03

    Update: Firoso, as mentioned in the comments you should be able to (I think - i.e. untested) be able to use the blend behavior components to cover your requirement.

    In addition to downloading and installing the SDK. Get a copy of the expression blend samples library (you'll need to click on Downloads from the following link): Expression Blend samples

    This library contains a prebuilt trigger called 'DataEventTrigger' which you can use to trigger actions in response to an event declared on your viewmodel.

    The blend SDK already has (from what I can tell) the other piece of the puzzle - it already includes an action which allows you to control storyboards. The name of this action is 'ControlStoryboardAction'.

    You should end up with some xaml which looks like this:

        
            
                
            
        
    

    Replace 'YourEvent' with the name of the event you have defined on your viewmodel, and replace 'Storyboard1' with the name of your storyboard. Of course the names will have to match exactly.

    Here are the xaml namespace definitions used:

    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:im="clr-namespace:Microsoft.Expression.Interactivity.Media;assembly=Microsoft.Expression.Interactions"
    xmlns:samples="clr-namespace:Expression.Samples.Interactivity;assembly=Expression.Samples.Interactivity"
    

    Original post, before edit:

    Suggest you look into Expression Blend Behaviors:

    information

    Blend SDK

    video on behaviors

提交回复
热议问题