我有控制模板:
Image x:Name="image" Height="100" Width="100"/>
<ContentPresenter x:Name="content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
事件点击背后的代码:
var btn = sender as MultipointButton;
var arg = e as MultipointMouseEventArgs;
Storyboard sb = new Storyboard();
ObjectAnimationUsingKeyFrames obj = new ObjectAnimationUsingKeyFrames();
obj.BeginTime = TimeSpan.Zero;
DiscreteObjectKeyFrame disobj = new DiscreteObjectKeyFrame();
disobj.KeyTime = TimeSpan.FromSeconds(0.2);
disobj.Value = CreateBitmapImage(Properties.Resources.SelectAnimation, 0, 0);
obj.KeyFrames.Add(disobj);
sb.Children.Add(obj);
btn.Name = "image";
this.RegisterName("image", btn);
Storyboard.SetTargetName(obj, btn.Name);
Storyboard.SetTargetProperty(obj, new PropertyPath(System.Windows.Controls.Image.SourceProperty));
sb.Begin(this);
this.UnregisterName("image");
但动画不起作用。