我正在使用DataTemplate,并且Background绑定到用户定义的Brush。
作为一个例子
<DataTemplate x:Key="ColumnText">
<TextBlock x:Name="TextCell"
Background="{Binding Column.CustBackground}" // DependencyProperty
IsReadOnly="True" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding **SomeProperty**}" Value="True">
//Animation Code Here
//.....
</DataTrigger>
</DataTemplate.Triggers>
如果有人可以指导我如何实现这一点,那就太棒了。
谢谢。
答案 0 :(得分:0)
简单路径上的5倍闪烁示例:mousedown:
的.xaml
<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication13"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Path Fill="Green" MouseDown="eventMarkerPath_MouseDown" Name="eventMarkerPath"
Data="M 5,15 L5,10 L10,0 L 0,0 L 5,10" >
<Path.Resources>
<Storyboard x:Key="storyboard">
<ColorAnimationUsingKeyFrames RepeatBehavior="5x" Duration="0:0:0.3" AutoReverse="True" Storyboard.TargetName="eventMarkerPath" Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="Green" ></EasingColorKeyFrame>
<EasingColorKeyFrame KeyTime="0:0:0.150" Value="Blue"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Path.Resources>
<i:Interaction.Triggers>
<i:EventTrigger SourceObject="{Binding}" EventName="AnimationTriggerEvent">
<i:EventTrigger.Actions>
<ei:ControlStoryboardAction Storyboard="{StaticResource storyboard}" ControlStoryboardOption="Play"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
</Path>
</Grid>
</Window>
的.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var animationItem = new MyItem();
this.DataContext = animationItem;
}
private void eventMarkerPath_MouseDown(object sender, MouseButtonEventArgs e)
{
((sender as FrameworkElement).DataContext as MyItem).CauseAnimation();
}
}
public class MyItem
{
public void CauseAnimation()
{
if (this.AnimationTriggerEvent != null)
this.AnimationTriggerEvent(this, null);
}
public event EventHandler AnimationTriggerEvent;
}