开发者

Event trigger for animation in Prism

开发者 https://www.devze.com 2023-03-31 21:16 出处:网络
I want to trigger an animation whenever a property is set (say \"StatusMessages\") in my ViewModel. The developer has already had the event set up:

I want to trigger an animation whenever a property is set (say "StatusMessages") in my ViewModel. The developer has already had the event set up:

 eventAggregator.GetEvent<ShowStatusEvent>().Subscribe(
                    (message) => ShowStatus(message), ThreadOption.UIThread
                );

 private void ShowStatus(MyApp.MyModelViews.StatusMessage stat开发者_运维问答usMessage){
   // set some values in status message view model
 }

What I don't know is what would be the Prism way of hooking up the event with my View (preferably in XAML) so that it triggers the animation. The following "DataTrigger" only works (i.e., triggers the animation) when the source is evaluated to a certain value, say changed from "Debug" to "Error". So if the value is set 12 times but to the same value, say "Debug" each time, the datatrigger only happens at most one time (from default to the new value, assuming they are not equal).

<DataTrigger Binding="{Binding DataContext.StatusMessages, ElementName=MyPanel}" Value="Error">...</DataTrigger>

The workaround now we came up with is to have a new bool property introduced especially for triggering the animation:

public bool CanBeginStoryboard{
    get
    {
        return canBeginStoryboard;
    }
    set
    {
       canBeginStoryboard = value;
       RaisePropertyChanged(() => CanBeginStoryboard);
    }
}
private void ShowStatus(MyApp.MyModelViews.StatusMessage statusMessage)
{
    CanBeginStoryboard = false;

    //// set some values in status message view model

    CanBeginStoryboard = true;
}
<DataTrigger Binding="{Binding DataContext.CanBeginStoryboard, ElementName=MyPanel}" Value="True">
<DataTrigger.EnterActions>
     <BeginStoryboard>...</BeginStoryboard>
</DataTrigger.EnterActions>

I assume there is a standard "Prism's way" of doing such things (like WPF "RoutedEvent">"EventTrigger"?), which is different from what we are doing here? BTW, we are using Prism 4. Thanks in advance.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号