I have found a few examples that relate to WPF, but none for Silverlight.
So, what is a working example of setting up a Microsoft.Expression.Interactivity.Core.DataTrigger in code?
Here is the code I currently have, though it doesn’t work (no exceptions, but nothing happens at runtime):
// Set up a storyboard
var duration = new Duration(TimeSpan.FromMilliseconds(400));
var animation = new ColorAnimation
{
To = Colors.White,
RepeatBehavior = RepeatBehavior.Forever,
AutoReverse = true,
Duration = duration
};
var sb = new Storyboard
{
RepeatBehavior = RepeatBehavior.Forever,
AutoReverse = true,
Duration = duration
};
sb.Children.Add(animation);
Storyboard.SetTarget(animation, fillBrush);
Storyboard.SetTargetProperty(animation, new PropertyPath("(SolidColorBrush.Color)"));
// Configure the data trigger
var focusTrigger = new DataTrigger
{
Binding = new Binding("IsFocussed")
{
Source = asset,
Mode = BindingMode.OneWay
},
Value = true
};
focusTrigger.Actions.Add(new ControlStoryboardAction
{
Storyboard = sb,
ControlStoryboardOption = ControlStoryboardOption.Play,
IsEnabled = true
});
asset.IsFocussed changes and raises change notifications via INotifyPropertyChanged.
In the end I was missing two bits:
Add the trigger to the brush:
Set the binding on the trigger using
BindingOperators.SetBinding, not theBindingproperty setter:I can’t quite see why the second point was necessary, but it seemed to be.
Hope that helps someone else out.