Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
In dem folgenden Beispiel wird veranschaulicht, wie mit der SeekAlignedToLastTick-Methode eines Storyboard eine beliebige Position in einer Storyboard-Animation synchron gesucht wird.
Beispiel
Im Folgenden wird das XAML-Markup für das Beispiel dargestellt.
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SDKSample.SeekStoryboardSynchronouslyExample">
<StackPanel Margin="20" >
<Rectangle Name="myRectangle"
Width="10" Height="20" Fill="#AA3333FF" HorizontalAlignment="Left" >
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard Name="myStoryboard" Duration="0:0:4">
<DoubleAnimation
Storyboard.TargetName="myRectangle"
Storyboard.TargetProperty="Width"
Duration="0:0:4" From="10" To="500"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
<!-- Use this slider to seek to different points of the Storyboard Duration
(in milliseconds). -->
<Slider Name="SeekSlider" ValueChanged="OnSliderValueChanged" Height="Auto"
Width="500" Minimum="0" Maximum="4000" HorizontalAlignment="Left" />
<!-- TextBlock displays the current time position of the Storyboard in milliseconds. -->
<TextBlock Name="PositionTextBlock"/>
</StackPanel>
</Page>
Im Folgenden wird der Code dargestellt, der zusammen mit dem obigen XAML-Code verwendet wird.
Imports System
Imports System.Media
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media.Animation
Namespace SDKSample
Partial Public Class SeekStoryboardSynchronouslyExample
Inherits Page
Private Sub OnSliderValueChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim sliderValue As Integer = CInt(SeekSlider.Value)
' The SeekAlignedToLastTick method should be used to seek a Storyboard synchronously.
myStoryboard.SeekAlignedToLastTick(myRectangle, New TimeSpan(0, 0, 0, 0, sliderValue), TimeSeekOrigin.BeginTime)
PositionTextBlock.Text = sliderValue.ToString()
End Sub
End Class
End Namespace
using System;
using System.Media;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace SDKSample
{
public partial class SeekStoryboardSynchronouslyExample : Page
{
private void OnSliderValueChanged(object sender, RoutedEventArgs e)
{
int sliderValue = (int)SeekSlider.Value;
// The SeekAlignedToLastTick method should be used to seek a Storyboard synchronously.
myStoryboard.SeekAlignedToLastTick(myRectangle, new TimeSpan(0, 0, 0, 0, sliderValue), TimeSeekOrigin.BeginTime);
PositionTextBlock.Text = sliderValue.ToString();
}
}
}