Question

Eh bien, comme le suggère le titre:

J'ai un story-board et je veux que c'est l'animation de commencer sans l'intervention de code. La raison de cette exigence est que je suis ciblage Silverlight intégré et je suis trop paresseux en ce moment recompiler ma demande aussi bien. Et, venant y penser, il sera plus facile de changer l'animation que dans l'avenir.

Est-ce que XAML ont une propriété pour faire fonctionner le story-board dès que les charges de XAML?

Était-ce utile?

La solution

Vous pouvez utiliser l'événement Loaded pour démarrer votre story-board

Voir MSDN pour un exemple: scénarimage (Silverlight)

Nous avons choisi l'exemple de 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>

L'objet Rectangle a des propriétés. Dans la propriété Triggers, nous avons défini un EventTrigger qui se déclenche lorsque cet événement se produira. Nous avons choisi l'événement Rectangle.Loaded, ce qui signifie qu'il se déclenche lorsqu'il est chargé;)

.

Nous ajoutons une propriété BeginStoryboard pour commencer notre story-board, et ajouter un storyboard. Cette animation utilisera un DoubleAnimation sur la propriété Opacité, ce qui signifie que dans une durée de 5 secondes, l'opacité va progressivement disparaître à zéro, et le dos (propriété AutoReverse) et il le fera toujours (la propriété RepeatBehaviour).

Autres conseils

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top