我们在故事板中有3个动画在Silverlight 4中工作正常,但在Silverlight 5中因上述错误而失败。动画非常简单:
<Storyboard x:Name="categoryChangeStoryboard">
<DoubleAnimation
Storyboard.TargetName="clueTransform"
Storyboard.TargetProperty="ScaleX"
Duration="0:0:0.4"
To="1.05"
RepeatBehavior="3x"
AutoReverse="True"
/>
<DoubleAnimation
Storyboard.TargetName="clueTransform"
Storyboard.TargetProperty="ScaleY"
Duration="0:0:0.4"
To="1.1"
RepeatBehavior="3x"
AutoReverse="True"
/>
<ColorAnimation
Duration="0:0:0.4"
Storyboard.TargetName="categoryForegroundBrush"
Storyboard.TargetProperty="Color"
From="Black"
To="LightGreen"
RepeatBehavior="3x"
AutoReverse="True"
/>
</Storyboard>
它的动画对象也非常简单:
<TextBlock x:Name="clue" Style="{StaticResource labelStyle}" Text="clue" FontSize="35" HorizontalAlignment="Right" MaxWidth="300" TextWrapping="Wrap" VerticalAlignment="Top" FontWeight="Bold" Margin="0,90,80,0" RenderTransformOrigin=".5,.5">
<TextBlock.Foreground>
<SolidColorBrush Color="Black" x:Name="categoryForegroundBrush" />
</TextBlock.Foreground>
<TextBlock.RenderTransform>
<CompositeTransform x:Name="clueTransform"/>
</TextBlock.RenderTransform>
</TextBlock>
当我们打电话时
categoryChangeStoryboard.Begin();
我们收到以下错误 - 仅适用于Silverlight 5:
{System.InvalidOperationException: Cannot resolve TargetName categoryForegroundBrush.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
at System.Windows.Media.Animation.Storyboard.Begin()
at BCL.FLY.FLYVisual.CoreStateUpdateEvent(Object sender, FLYStateUpdateEventArgs e)
at BCL.FLY.FLYCore.OnStateUpdateEvent(FLYStateUpdateEventArgs e)
at BCL.FLY.FLYCore.Report(String msg, GameEventType t, Butterfly b)
at BCL.FLY.FLYCore.DebugGotoLevel(Int32 i)
at BCL.FLY.FLYVisual.DebugGotoLevel(Int32 n)
at BCL.FLY.FLYGame.GotoLevel(Int32 i)
at C8Live.MainPage.lvlSkip_SelectionChanged(Object sender, SelectionChangedEventArgs e)
at System.Windows.Controls.Primitives.Selector.OnSelectionChanged(SelectionChangedEventArgs e)
at System.Windows.Controls.Primitives.Selector.InvokeSelectionChanged(List`1 unselectedItems, List`1 selectedItems)
at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
at System.Windows.Controls.Primitives.Selector.NotifyListItemSelected(ListBoxItem listBoxItem, Boolean isSelected)
at System.Windows.Controls.Primitives.Selector.OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b)
at System.Windows.Controls.Primitives.Selector.OnListBoxItemClicked(ListBoxItem item)
at System.Windows.Controls.ListBoxItem.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)}
有没有人有任何想法?删除单个ColorAnimation确实可以解决问题,但我们更愿意保留它。
答案 0 :(得分:0)
我已将此问题转载如下。
因为您在xaml中设置了Foreground并将x:Name添加到画笔中,所以后面的代码无法更改。应用样式的顺序首先是Style资源,然后是控件内部的任何内容,覆盖样式。
就像我说的那样,改变后面代码中的颜色会重现问题,因为它不包含name属性。正如您在下一张图片中看到的那样,我已经找到了解决方案,那就是设置DependecyProperty NameProperty
的值。
添加代码
solidColorBrush.SetValue(NameProperty, "categoryForegroundBrush");
你不应该再遇到这个问题了。