I did this with a DataTrigger and bound it to a property in my ViewModel. When the FlashingBackGround property is set to ON, the storyboard animation begins.
Also do not forget to include in your project a link to "Microsoft.Expression.Interactions"
XAML: (this happens directly in the root of the node)
<Window xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Name="window" > ... <i:Interaction.Triggers> <ei:DataTrigger Binding="{Binding FlashingBackground, Mode=OneWay}" Value="ON"> <ei:ControlStoryboardAction Storyboard="{StaticResource MyAnimation}" ControlStoryboardOption="Play"/> </ei:DataTrigger> </i:Interaction.Triggers> ... </Window>
ViewModel:
private void TurnOnFlashingBackround() { this.FlashingBackground = "ON"; } private string _FlashingBackround = "OFF"; public string FlashingBackground { get { return this._FlashingBackround; } private set { if (this.FlashingBackground == value) { return; } this._FlashingBackround = value; this.OnPropertyChanged("FlashingBackground"); } } public new event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged( this, new PropertyChangedEventArgs(propertyName)); } }
Finally, the Viewmodel must inherit from "INotifyPropertyChanged"
CowboyBebop May 12 '11 at 15:54 2011-05-12 15:54
source share