private Storyboard PrepareShowStory()
{
Storyboard story = new Storyboard();
DoubleAnimation animation;
animation = new DoubleAnimation();
animation.From = 0;
animation.To = 100;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
Storyboard.SetTarget(animation, image1);
//Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Height)"));
story.Children.Add(animation);
story.AutoReverse = true;
story.RepeatBehavior = new RepeatBehavior(3); //RepeatBehavior.Forever;
return story;
}
story.AutoReverse
是否返回,如上面的,先是从0到100,然后再自动由100到0
animation.Duration 执行的间隔
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Popup x:Name="ProgressPopup" Width="300" IsOpen="False" HorizontalAlignment="Center"
VerticalAlignment="Top" d:LayoutOverrides="Width, HorizontalMargin" Margin="89,203,91,0">
<Border BorderThickness="10" BorderBrush="Black" Background="DarkGray" Padding="30,30">
<StackPanel>
<TextBlock MaxHeight="100" Foreground="White" FontWeight="Bold" FontSize="36" x:Name="txt" Text="1">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard> <Storyboard >
<DoubleAnimation AutoReverse="True" Duration="0:0:1"
From="1.0" RepeatBehavior="Forever" Storyboard.TargetName="txt" Storyboard.TargetProperty="Opacity" To="0.0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</StackPanel>
</Border>
</Popup>
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Height="246" HorizontalAlignment="Left" Margin="101,182,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="197" DataContext="{Binding}" Source="/PhoneApp1;component/Images/7.jpg" />
</Grid>
</Grid>
{
Storyboard _timer = new Storyboard();
Storyboard story;
int i = 0;
// 构造函数
public MainPage()
{
InitializeComponent();
_timer.Duration = TimeSpan.FromMilliseconds(10);
_timer.Completed += new EventHandler(_timer_Completed);
_timer.Begin();
i = Convert.ToInt32(txt.Text);
}
void _timer_Completed(object sender, EventArgs e)
{
if (i <= txt.MaxHeight)
{
i++;
this.txt.Text = i.ToString();
_timer.Begin();
return;
}
this.Dispatcher.BeginInvoke(new Action(() => { ProgressPopup.IsOpen = false; }));
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
//ProgressPopup.IsOpen = true;
// this.Dispatcher.BeginInvoke(new Action(() => ProgressPopup.IsOpen = true));
story = PrepareShowStory();
story.Begin();
}
private Storyboard PrepareShowStory()
{
Storyboard story = new Storyboard();
DoubleAnimation animation;
animation = new DoubleAnimation();
animation.From = 0;
animation.To = 100;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
Storyboard.SetTarget(animation, image1);
//Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)"));
Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Height)"));
story.Children.Add(animation);
story.AutoReverse = true;
story.RepeatBehavior = new RepeatBehavior(3); //RepeatBehavior.Forever;
return story;
}
}