我有一個Button
控件,我正在定義一個自定義模板。使用一些Storyboard
的我可以用DoubleAnimation
成功操縱控制屬性,命名轉換和效果;問題出現了,使用PointAnimation
時,一個InvalidOperationException
被拋出,每VS:Cannot resolve TargetName OverlayEllipse.
將PointAnimation的TargetName設置爲資源拋出的名稱InvalidOperationException(XAML/Silverlight)
的動畫代碼發起的,簡單地說:
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
PopUpStoryboard.Begin();
}
和相關的XAML:
<Button ...>
<Button.Resources>
<RadialGradientBrush
x:Name="OverlayBrush" ...>
<RadialGradientBrush.GradientStops>
...
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
<Storyboard x:Name="PopUpStoryboard">
...
<PointAnimation
Storyboard.TargetName="OverlayEllipse"
Storyboard.TargetProperty="(Shape.Fill)(RadialGradientBrush.GradientOrigin)"
Duration="0:0:.1"
To="0.9,1.2"/>
</Storyboard>
<Button.Resources>
<Button.Style>
<Style TargetType="Button">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
...
<Ellipse x:Name="OverlayEllipse" Fill="{StaticResource OverlayBrush}"/>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
Ellipse
可以解析資源,很明顯,因爲它顯示得很好,異常直接從Storyboard.Begin
調用拋出。我怎樣才能糾正我爲了讓Storyboard
能夠按名稱解析資源?
我曾想過使用StaticResource
綁定,但是,考慮到它直接指向對象而不是它的名稱,它不起作用。我只是試圖設置Target
,而不是TargetName
,使用StaticResource
結合 - 這給了我一個生成錯誤(很奇怪?)指出:The property 'Target' does not exist on the type 'PointAnimation' in the namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation '.
感謝。
當我回家的時候給我一個鏡頭,要做幾個小時的工作 - 會讓你知道它是如何變成的,謝謝。 – 2011-01-20 11:05:16