0
在故事板中有3個動畫可在Silverlight 4中正常工作,但在Silverlight 5中出現上述錯誤時失敗。動畫是非常簡單的:Silverlight 5.0 SolidColorBrush的ColorAnimation以「無法解析目標名稱」失敗
<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確實解決了這個問題,但我們寧願保留它。
請問labelStyle是否設置了前景刷? – cadrell0 2012-03-07 16:13:19
這是非常奇怪的。我已將代碼複製到一個簡單的項目中,一切正常。如果可以,你可以分享風格嗎?在我看來,你的風格覆蓋了你的Textblock的Foreground顏色,因此無法找到被覆蓋的SolidColorBrush x:命名的categoryForeGroundBrush – 2012-03-07 20:57:50
@Danimal,我在示例項目中運行了你的代碼,它工作正常。我需要看到你的labelStyle來重現這一點。 – KodeKreachor 2012-03-08 02:48:03