我有以下问题。我正在寻找鼠标悬停上的图标的颜色值的动画(并且一旦鼠标离开就将其动画化)。为了达到这个目的,我创建了一个在MouseEnter上触发的新ColorAnimation。动画的属性路径是“(Path.Fill)。(SolidColorBrush.Color)”。但是,当运行这个给出了错误; 'Fill'属性不指向路径'(Path.Fill)。(SolidColorBrush.Color)'中的DependencyObject。虽然我认为我明白错误意味着什么,但我不知道应该使用哪些属性路径。有任何想法吗?预先感谢您的时间。请让我知道是否有什么不清楚。MouseEnter/MouseLeave(WPF)上的VisualBrush的动画颜色值
Ps。如果有人对如何放置“图标/路径”资源有更好的想法,我非常感激。
代码;
ColorAnimation mouseEnterColorAnimation = new ColorAnimation {
To = Colors.Yellow,
Duration = TimeSpan.FromSeconds(1)
};
Storyboard.SetTargetName(mouseEnterColorAnimation, "DeleteIconGrid");
Storyboard.SetTargetProperty(mouseEnterColorAnimation, new PropertyPath("Path.Fill).(SolidColorBrush.Color)"));
Storyboard mouseEnterStoryboard = new Storyboard();
mouseEnterStoryboard.Children.Add(mouseEnterColorAnimation);
mouseEnterStoryboard.Begin(this);
Xaml;
<Grid x:Name="Grid" Background="Transparent" Width="100" Height="100" MouseDown="Grid_MouseDown" MouseEnter="Grid_MouseEnter" MouseLeave="Grid_MouseLeave" >
<Grid x:Name="DeleteIconGrid" Width="50" Margin="0,0,0,14"><Grid.Background><VisualBrush Visual="{StaticResource Icon-Delete}" Stretch="Uniform" /></Grid.Background></Grid>
<Label Content="Delete icon" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="6" Foreground="{DynamicResource Gray}"></Label>
</Grid>
资源;
<Canvas x:Key="Icon-Delete" Background="Transparent">
<Path Stretch="Uniform" Fill="LightSlateGray" Data="F1 M 4.70432,0L 0.0480347,4.77802L 7.00842,11.6812L 0,18.7292L 4.70432,23.46L 11.6647,16.412L 18.6252,23.46L 23.3774,18.7774L 16.369,11.6812L 23.3294,4.77802L 18.6252,0L 11.6647,6.9986L 4.70432,0 Z" />
</Canvas>
谢谢Sheridan的回复。如果我理解正确,则表明由于VisualBrush没有Color属性,所以我应该为SolidColorBrush本身制作动画。但是,这正是我的目标与我的PropertyPath权利? (“(Path.Fill)。(SolidColorBrush.Color)”) 我应该定位不同的属性吗? – WalterB
使用“VisualBrush”时,您无法定位“SolidColorBrush.Color”属性。除非实际设置了'VisualProperty'的'Visual'的动画,否则'VisualBrush'颜色不能被动画化。 – Sheridan
这意味着我应该将VisualProperty的可视化为目标吗?我将如何通过PropertyPath来定位Visual的颜色属性? – WalterB