2009-12-28 1 views
3

에 스토리 보드 애니메이션을 시작합니다. 이 요구 사항의 이유는 Silverlight Embedded를 대상으로하고 있으며 현재 응용 프로그램을 다시 컴파일하기에는 너무 게으른 것입니다. 생각 해보니 장래에 애니메이션을 변경하는 것이 더 쉬울 것입니다.XAML 속성은 잘로드

XAML에는 xaml이로드되는 즉시 스토리 보드를 실행할 수있는 속성이 있습니까?

답변

14

당신은 예를 들어 스토리 보드를

참조 MSDN을 시작로드 이벤트를 사용할 수 있습니다 Storyboard (Silverlight)

은 MSDN에서 예를 골랐다 :

<Canvas 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Rectangle 
    x:Name="MyAnimatedRectangle" 
    Width="100" 
    Height="100" 
    Fill="Blue"> 
    <Rectangle.Triggers> 

     <!-- Animates the rectangle's opacity. 
      This is the important part, the EventTrigger which will start our animation --> 

     <EventTrigger RoutedEvent="Rectangle.Loaded"> 
     <BeginStoryboard> 
      <Storyboard> 
      <DoubleAnimation 
       Storyboard.TargetName="MyAnimatedRectangle" 
       Storyboard.TargetProperty="Opacity" 
       From="1.0" To="0.0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" /> 
      </Storyboard> 
     </BeginStoryboard> 
     </EventTrigger> 
    </Rectangle.Triggers> 
    </Rectangle> 
</Canvas> 

사각형이 속성이있는 객체입니다. Triggers 속성에서이 이벤트가 발생할 때 발생하는 EventTrigger를 정의했습니다. Rectangle.Loaded 이벤트를 선택합니다. 즉,로드 될 때 실행됩니다.).

우리는 스토리 보드를 시작하고 스토리 보드를 추가하기 위해 BeginStoryboard 속성을 추가합니다. 이 애니메이션은 Opacity 속성에 DoubleAnimation을 사용합니다. 즉, 5 초 동안 불투명도가 점차 0으로 떨어지고 뒤로 (AutoReverse 속성) 사라져서 영원히 반복됩니다 (RepeatBehaviour 속성).

+0

나는 곧바로 MSDN (부끄러움)을 확인하지 않고 갔다. MSDN에서 내가 찾는 행동과 비슷한 점이없는 것 같습니다. 스토리 보드는 코드에서 시작해야합니다 ... 제안은 여전히 ​​코드 작성/변경을 포함합니다. – Shaihi

+0

XAML을 코드로 간주 할 수 있다면 그래, 작동하려면 XAML을 약간 써야합니다.) – Arcturus

+0

OK. 나는 XAML에서 이벤트를 사용하는 방법을 읽었을 때 문제가 해결 될 때를 대비하여 읽어 볼 것입니다. 감사합니다. – Shaihi

2
<UserControl x:Class="SOSMVVM.AniM11" 
    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' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'> 


    <StackPanel Margin="5"> 
     <Rectangle Name="rect3" Fill="Blue" Margin="2" Width="20" 
     Height="20" HorizontalAlignment="Left" /> 
     <Button Margin="2,20,0,0" HorizontalAlignment="Left" 
     Content="Start Animations" Width="100"> 
      <Button.Triggers> 
       <EventTrigger RoutedEvent="Button.Click"> 
        <EventTrigger.Actions> 
         <BeginStoryboard> 
          <Storyboard> 

           <DoubleAnimation 
        Storyboard.TargetName="rect3" Storyboard.TargetProperty="Width" 
        From="20" To="400" Duration="0:0:10" SpeedRatio="0.5" /> 


          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger.Actions> 
       </EventTrigger> 
      </Button.Triggers> 
     </Button> 
    </StackPanel> 


</UserControl> 
+2

설명이 도움이되었을 것입니다 .. –