방법: 동기적으로 Storyboard 검색
다음 예제는 Storyboard의 SeekAlignedToLastTick 메서드를 사용하여 동기적으로 스토리보드 애니메이션의 임의 위치로 이동하는 방법을 보여줍니다.
XAML 태그
다음은 샘플에 대한 XAML 태그입니다.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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>
코드
다음은 위의 XAML 코드와 함께 사용되는 코드입니다.
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();
}
}
}
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
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback