2
我正在C#中開發wpf應用程序。下面的xaml代碼對我來說工作正常。如何在C#中設置Storyboard.TargetProperty?
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="DefaultVisualState">
<Storyboard/>
</VisualState>
<VisualState x:Name="FocusVisualState">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="CircleEllipse1">
<EasingColorKeyFrame KeyTime="0" Value="#FF0004FF"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Background).(SolidColorBrush.Color)" Storyboard.TargetName="TextBlock1">
<EasingColorKeyFrame KeyTime="0" Value="#FFBCB0B0"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
同樣的代碼,我用C#編寫
EasingColorKeyFrame easingColorKeyFrameObj = new EasingColorKeyFrame();
easingColorKeyFrameObj.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
easingColorKeyFrameObj.Value = Colors.Red;
ColorAnimationUsingKeyFrames colorAnimationUsingKeyFramesObj = new ColorAnimationUsingKeyFrames();
colorAnimationUsingKeyFramesObj.KeyFrames.Add(easingColorKeyFrameObj);
Storyboard.SetTargetName(colorAnimationUsingKeyFramesObj, "CircleEllipse1");
Storyboard.SetTargetProperty(
colorAnimationUsingKeyFramesObj, new PropertyPath("Color"));
Storyboard myStoryboard = new Storyboard();
myStoryboard.Children.Add(colorAnimationUsingKeyFramesObj);
myStoryboard.Begin(this, true);
在上面的代碼中,我應該怎麼設置Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
和Storyboard.TargetProperty="(TextElement.Background).(SolidColorBrush.Color)"
在C#