2
使用DoubleAnimation是,附加屬性Canvas.Left應逐步設置爲100:內ItemsControl的橢圓移動動畫與帆布模板
<Ellipse Width="30" Height="30" Fill="Purple">
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:5" Storyboard.TargetProperty="(Canvas.Left)" To="100" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
,這個橢圓的(對於我的視圖模型一個DataTemplate的一部分)被綁定到ItemsControl的通過的ItemsSource:
<ItemsControl ItemsSource="{Binding Components}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="Beige" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
然而,在加載時橢圓,會出現以下情況例外:
Cannot animate the 'Left' property on a 'System.Windows.Shapes.Ellipse' using a 'System.Windows.Media.Animation.DoubleAnimation'.
但動畫的目標屬性被指定爲「Canvas.Left」而不是「左」?
ItemsControl的是不相關的 - 你可以只用帆布內的橢圓XAML重現該問題。 – 2011-03-29 02:32:04