【发布时间】:2014-04-27 22:23:36
【问题描述】:
我正在为三个不同的图像使用一个动画。我将如何使用相同的 Storyboard 来定位所有三个?谢谢....
C#
public TheGame()
{
InitializeComponent();
CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
FadeImageStoryboard.Begin();
}
XAML;
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="Capitals.TheGame"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" Height="480" Width="640" KeyDown="UserControl_KeyDown" >
<Canvas x:Name="LayoutRoot" Background="#FF6AC3FF" >
<Grid x:Name="MyGrid" Height="235" Canvas.Left="10" Canvas.Top="85" Width="620" >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<Storyboard x:Name="FadeImageStoryboard">
<DoubleAnimation From="1.0"
To="0.3"
Duration="0:0:2"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="cloud1"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</Grid.Resources>
<StackPanel Grid.RowSpan="2">
<Image x:Name="cloud1" Source="Cloud.png" Height="115" Width="184" Margin="29,78,407,42" />
<Image x:Name="cloud2" Source="Cloud.png" Height="115" Width="184" Margin="218,78,218,42"
Opacity="{Binding Opacity, ElementName=cloud1}"/>
<Image x:Name="cloud3" Source="Cloud.png" Height="115" Width="184" Margin="402,78,34,42"
Opacity="{Binding Opacity, ElementName=cloud1}"/>
</StackPanel>
<sdk:Label Height="28" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Canvas.Left="255" Canvas.Top="52" Width="120" Content="Capitals" Background="#FF68A0D8" Foreground="#FF6AC3FF" FontFamily="Comic Sans MS" FontStyle="Italic" FontWeight="Bold" FontSize="20" Margin="250,-33,250,123"/>
<sdk:Label x:Name="detailLabel" HorizontalAlignment="Center" VerticalAlignment="Center" Height="28" Canvas.Left="405" Canvas.Top="52" Canvas.ZIndex="1" FontFamily="Comic Sans MS" FontSize="14" Foreground="#FF5D5D5D" Content="PlayerName| PlayerScore" Margin="150,10,150,80" Width="320"/>
<sdk:Label x:Name="option1" HorizontalAlignment="Center" Height="28" Margin="70,0,430,89" Grid.Row="1" VerticalAlignment="Center" Width="120" Foreground="#FF5D5D5D" FontFamily="Comic Sans MS" FontSize="13" Content="Maybe..."/>
<sdk:Label x:Name="option2" HorizontalAlignment="Center" Height="28" Margin="250,0,250,89" Grid.Row="1" VerticalAlignment="Center" Width="120" Foreground="#FF5D5D5D" FontFamily="Comic Sans MS" FontSize="13" Content="Wrong?"/>
<sdk:Label x:Name="option3" HorizontalAlignment="Center" Height="28" Margin="440,0,60,89" Grid.Row="1" VerticalAlignment="Center" Width="120" Foreground="#FF5D5D5D" FontFamily="Comic Sans MS" FontSize="13" Content="Correct?"/>
</Grid>
<sdk:Label x:Name="questionLabel" HorizontalAlignment="Center" VerticalAlignment="Center" Height="28" Canvas.Left="80" Canvas.Top="320" Width="480" Foreground="#FF5D5D5D" FontFamily="Comic Sans MS" FontSize="20" Content="Capital of which country?"/>
</Canvas>
【问题讨论】:
-
我尝试从 xaml 中删除 targetname 并在我的类中添加目标;
(this.Resources["FadeImageStoryboard"] as Storyboard).Begin(cloud1,true);等等...但它不是这样工作的。 -
您没有将您的问题标记为已回答吗?这个很旧,我已经忘记了它,直到另一个支持它。
-
没有答案被标记为正确@ChrisW。如你所愿接受。
-
啊,如果不是答案,请不要标记它。也许我应该问一下它是否对你有用。我只是碰巧注意到你在这里提出的问题中只有一两个被标记过。别担心,周末愉快。
标签: c# silverlight xaml storyboard