1 <Grid Width="300" Height="460"> 2 <Grid.RowDefinitions> 3 <RowDefinition Height="*"/> 4 <RowDefinition Height="60"/> 5 <RowDefinition Height="100"/> 6 </Grid.RowDefinitions> 7 <Grid.Triggers> 8 <EventTrigger SourceName="btnStart" RoutedEvent="Button.Click"> 9 <BeginStoryboard x:Name="myImageBStoryboard" > 10 <Storyboard CurrentTimeInvalidated="Storyboard_CurrentTimeInvalidated"> 11 <DoubleAnimation Storyboard.TargetName="myImageB" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="00:00:05"> 12 13 </DoubleAnimation> 14 </Storyboard> 15 </BeginStoryboard> 16 </EventTrigger> 17 <EventTrigger SourceName="btnPause" RoutedEvent="Button.Click"> 18 <PauseStoryboard BeginStoryboardName="myImageBStoryboard"></PauseStoryboard> 19 </EventTrigger> 20 <EventTrigger SourceName="btnResume" RoutedEvent="Button.Click"> 21 <ResumeStoryboard BeginStoryboardName="myImageBStoryboard"></ResumeStoryboard> 22 </EventTrigger> 23 <EventTrigger SourceName="btnStop" RoutedEvent="Button.Click"> 24 <StopStoryboard BeginStoryboardName="myImageBStoryboard"></StopStoryboard> 25 </EventTrigger> 26 <EventTrigger SourceName="btnMiddle" RoutedEvent="Button.Click"> 27 <SeekStoryboard BeginStoryboardName="myImageBStoryboard" Offset="00:00:02"> 28 </SeekStoryboard> 29 </EventTrigger> 30 </Grid.Triggers> 31 <Grid Grid.Row="0" Grid.Column="0" > 32 <Image x:Name="myImageA" Source="Images/A.jpg" Height="300" Width="300" Stretch="Fill"></Image> 33 <Image x:Name="myImageB" Source="Images/B.jpg" Height="300" Width="300" Stretch="Fill" ></Image> 34 </Grid> 35 <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal"> 36 <Button x:Name="btnStart" Content="Start" Width="50" Height="40" Margin="3" ></Button> 37 <Button x:Name="btnPause" Content="Pause" Width="50" Height="40" Margin="3" ></Button> 38 <Button x:Name="btnResume" Content="Resume" Width="50" Height="40" Margin="3" ></Button> 39 <Button x:Name="btnStop" Content="Stop" Width="50" Height="40" Margin="3" ></Button> 40 <Button x:Name="btnMiddle" Content="SeekToMiddle" Width="50" Height="40" Margin="3" ></Button> 41 </StackPanel> 42 <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Vertical"> 43 <TextBlock x:Name="myTextBlock" FontSize="13" Foreground="Red"> </TextBlock> 44 <ProgressBar x:Name="myProgressBar" Height="35" Background="White" Width="300" > 45 <ProgressBar.Foreground> 46 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 47 <GradientStop Color="#FF4DF22F" Offset="0.505" /> 48 <GradientStop Color="#FFEFF5F1" Offset="1" /> 49 <GradientStop Color="#FFF8F8F8" Offset="0.013" /> 50 </LinearGradientBrush> 51 </ProgressBar.Foreground> 52 </ProgressBar> 53 </StackPanel> 54 </Grid>
1 public partial class MainWindow : Window 2 { 3 public MainWindow() 4 { 5 InitializeComponent(); 6 } 7 8 private void Storyboard_CurrentTimeInvalidated(object sender, EventArgs e) 9 { 10 Clock storyboardClock = sender as Clock; 11 if (storyboardClock.CurrentProgress != null) 12 { 13 myTextBlock.Text = storyboardClock.CurrentTime.ToString(); 14 myProgressBar.Value = (double)storyboardClock.CurrentProgress*100;(注意这儿storyboardClock.CurrentProgres值范围是0至1) 15 System.Diagnostics.Debug.WriteLine(myProgressBar.Value); 16 } 17 else 18 { 19 myProgressBar.Value = 0; 20 myTextBlock.Text = "Stopped"; 21 } 22 } 23 }
时间: 2024-10-10 10:53:47