我正在尝试动态创建当您将鼠标悬停在它们上时会放大的图像。我发现这篇博客文章http://tozon.info/blog/post/2007/10/14/Three-ways-to-make-your-WPF-images-pop-out-on-MouseOver.aspx展示了如何使用情节提要做到这一点。
它看起来很简单,我已将 StoryBoard xaml 添加到 App.xaml
现在我需要弄清楚如何将它们添加到我用 C# 构建的图像中
必须创建的 xml 看起来像这样
<Image Source="[Bitmap]" >
<Image.Triggers>
<EventTrigger RoutedEvent="Image.MouseEnter" >
<BeginStoryboard Storyboard="{StaticResource ExpandStoryboard}" />
</EventTrigger>
<EventTrigger RoutedEvent="Image.MouseLeave" >
<BeginStoryboard Storyboard="{StaticResource ShrinkStoryboard}" />
</EventTrigger>
</Image.Triggers>
<Image.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
</Image>
我有用 C# 创建的图像、情节提要和 RenderTransform(我认为),但我不确定如何将情节提要添加为 EventTriggers。
System.Windows.Controls.Image _Image = new System.Windows.Controls.Image();
_Image.Source = this.BitmapToBitmapImage(_Bitmap); // This bit is not really relevant for this question. It works fine though.
ScaleTransform _OriginalScale = new ScaleTransform();
_OriginalScale.ScaleX = 1;
_OriginalScale.ScaleY = 1;
_Image.RenderTransform = _OriginalScale;
Storyboard _ExpandStory = (Storyboard)Application.Current.FindResource("ExpandStoryboard");
Storyboard _ShrinkStory = (Storyboard)Application.Current.FindResource("ShrinkStoryboard");
_Image.Triggers.Add(WHAT GOES HERE);