我正在尝试将鼠标突出显示到代码生成的路径(Path class i mean)。问题是我没有使用某些XAML模板绑定该代码只是在C#中生成它。我已经有了我的形状(Path),但是我无法添加Style来使用它。
这是我的代码:
Setter setter = new Setter();
setter.Property = Path.FillProperty;
setter.Value = new SolidColorBrush(Colors.LightYellow);
EventTrigger eTrigger = new EventTrigger();
eTrigger.RoutedEvent = UIElement.MouseEnterEvent;
Style styleMouseIn = new Style();
styleMouseIn.Setters.Add(setter);
styleMouseIn.TargetType = typeof(Path);
styleMouseIn.Triggers.Add(eTrigger);
BeginStoryboard mouseInAnim = new BeginStoryboard();
mouseInAnim.Storyboard = new Storyboard();
eTrigger.Actions.Add(mouseInAnim);
//path.Style.Setters.Add(setter);
//path.Style.Triggers.Add(eTrigger);
path.Style = styleMouseIn;
但它不起作用。
编辑:
Setter setter = new Setter();
setter.Property = Path.FillProperty;
setter.Value = new SolidColorBrush(Colors.LightYellow);
ColorAnimation anim1 = new ColorAnimation();
anim1.To = Colors.Yellow;
anim1.Duration = new Duration(TimeSpan.FromSeconds(1));
anim1.FillBehavior = FillBehavior.HoldEnd;
BeginStoryboard StoryBoad = new BeginStoryboard();
StoryBoad.Storyboard = new Storyboard();
Storyboard.SetTargetProperty(anim1, new PropertyPath(SolidColorBrush.ColorProperty));
EventTrigger eTrigger = new EventTrigger();
eTrigger.RoutedEvent = UIElement.MouseEnterEvent;
eTrigger.Actions.Add(StoryBoad);
Style styleMouseIn = new Style();
styleMouseIn.Setters.Add(setter);
styleMouseIn.TargetType = typeof(Path);
styleMouseIn.Triggers.Add(eTrigger);
StoryBoad.Storyboard.Children.Add(anim1);
path.Style = styleMouseIn;
新版本:F
答案 0 :(得分:0)
我有这个。 这条线是解决方案:
Storyboard.SetTargetProperty(anim1, new PropertyPath("Fill.Color"));