0
A
回答
1
你會使用一個DoubleAnimationUsingKeyFrames(參見MSDN文檔here C#中使用示例)和動畫控件的Opacity財產。
0
您可以在XAML中定義一個操縱不透明度的故事板。下面的完整的XAML的例子說明這一點:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Fading Rectangle Example">
<StackPanel Margin="10">
<Rectangle
Name="MyRectangle"
Width="100"
Height="100"
Fill="Blue">
</Rectangle>
<Button Name="BeginButton">Begin</Button>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Button.Click" SourceName="BeginButton">
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyRectangle"
Storyboard.TargetProperty="(Rectangle.Opacity)"
From="1.0" To="0.0" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</Page>
運行從C#動畫,根據您的要求,也有可能:
public void DoAnimation()
{
Storyboard opacityStoryboard = FindResource("MyBeginStoryboard") as Storyboard;
opacityStoryboard.Begin(this);
}
兩種方法的結合是定義在XAML的動畫和在C#中激活它。
使用這個模式,你可以定義兩個故事板:
- 改變窗體的Opacity屬性從0.0到1.0以上5秒
- 窗體的Opacity屬性的變化,從1.0到0.0故事板分鏡腳本3秒以上
您可以修改上面的例子來做到這一點作爲一個獨立的樣本:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Fading Rectangle Example">
<StackPanel Margin="10">
<Rectangle
Name="MyRectangle"
Width="100"
Height="100"
Fill="Blue">
</Rectangle>
<Button Name="FadeInButton">Fade In</Button>
<Button Name="FadeOutButton">Fade Out</Button>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Button.Click" SourceName="FadeInButton">
<BeginStoryboard Name="FadeInStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyRectangle"
Storyboard.TargetProperty="(Rectangle.Opacity)"
From="0.0" To="1.0" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Button.Click" SourceName="FadeOutButton">
<BeginStoryboard Name="FadeOutStoryboard">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyRectangle"
Storyboard.TargetProperty="(Rectangle.Opacity)"
From="1.0" To="0.0" Duration="0:0:3" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</Page>
使用上面顯示的「從C#運行故事板」模式,您可以在適當的時候在C#代碼中運行每個故事板。
相關問題
- 1. jQuery動畫淡入淡出
- 2. android:淡入淡出動畫
- 3. 淡入淡出動畫Swift
- 4. CSS3動畫/淡入淡出
- 5. 淡入淡出動畫UITableViewCell
- 6. CSS動畫淡入淡出
- 7. 淡入淡出動畫
- 8. 動畫淡入淡出
- 9. 淡入淡出動畫
- 10. CSS3淡入淡出動畫
- 11. 淡入淡出動畫(UIViewAnimation)
- 12. 動畫UILabel淡入/淡出
- 13. 淡入淡出動畫
- 14. NSGradient淡入淡出/動畫
- 15. jquery動畫和淡入/淡出問題
- 16. jQuery淡入淡出,動畫和切換?
- 17. 控制淡入和淡出的動畫
- 18. 淡入淡出淡入淡出下一個div和動畫中的子元素
- 19. jquery淡出,淡入淡出,等待,淡入淡出
- 20. .NET WPF窗口淡入淡出和動畫
- 21. 在Android中動畫淡入淡出
- 22. 淡入淡出相關的div動畫
- 23. CSS廣場淡入淡出動畫
- 24. 淡入淡出動畫上UIButtons
- 25. JQuery Masonry淡入淡出動畫
- 26. TextView動畫 - 淡入,等待,淡出
- 27. Jquery淡入淡出動畫問題
- 28. 淡入,淡出動畫到uilabel
- 29. 連續淡入淡出動畫
- 30. 優化淡入淡出框動畫
我使用DoubleAnimationUsingKeyFrames嘗試了動畫。雖然淡入進行中,我可以看到某種閃爍。 TranslationAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0.0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); TranslationAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1.0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(5))));淡入不順暢。 – user209293 2010-10-06 05:45:39
我不得不看完整的代碼,看看有什麼不對。 – bitbonk 2010-10-06 06:20:38
PageViewObj.RegisterName(「Animation」,PageViewObj); sb = new System.Windows.Media.Animation.Storyboard(); sb.BeginTime = TimeSpan.FromMilliseconds(0); TranslationAnimation = new ystem.Windows.Media.Animation.DoubleAnimationUsingKeyFrames(); TranslationAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0.0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); TranslationAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1.0 ,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(5)))); TranslationAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1.0,KeyTime.FromTimeSpan(TimeSpan.FromSeconds(10)))); – user209293 2010-10-06 07:06:19