Nasıl yapılır: Özellik Değeri Değiştiğinde bir Animasyonu Tetikleme
Bu örnekte, Trigger bir özellik değeri değiştiğinde başlatmak Storyboard için 'nin nasıl kullanılacağı gösterilmektedir. içinde , TriggerStyleControlTemplateveya DataTemplatekullanabilirsiniz.
Örnek
Aşağıdaki örnekte, özelliği olduğunda IsMouseOvertrue
öğesine animasyon Opacity eklemek için bir Button kullanılırTrigger.
<!-- PropertyTriggerExample.xaml
Shows how to use property triggers to start animations. -->
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Animate Properties with Storyboards">
<Page.Resources>
<Style x:Key="PropertyTriggerExampleButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Opacity" Value="0.25" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0.25" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</Page.Resources>
<StackPanel Margin="20">
<Button Style="{StaticResource PropertyTriggerExampleButtonStyle}">
Move the mouse over me.
</Button>
</StackPanel>
</Page>
Özellik Trigger nesneleri tarafından uygulanan animasyonlar, yöntemler kullanılarak Storyboard başlatılan animasyonlardan veya animasyonlardan daha EventTrigger karmaşık bir şekilde davranır. Diğer Trigger nesneler tarafından tanımlanan animasyonlarla "iletim" yaparlar, ancak ve yöntemiyle tetiklenen animasyonlar oluştururlar EventTrigger .
Ayrıca bkz.
.NET Desktop feedback
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin