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. 动画UILabel淡入/淡出
- 2. 淡入淡出动画(UIViewAnimation)
- 3. 淡入淡出动画
- 4. jQuery淡入淡出,动画和切换?
- 5. jquery动画和淡入/淡出问题
- 6. 淡入淡出淡入淡出下一个div和动画中的子元素
- 7. .NET WPF窗口淡入淡出和动画
- 8. 淡入,淡出动画到uilabel
- 9. 淡入淡出相关的div动画
- 10. jQuery调用CSS3淡入淡出动画?
- 11. @keyframes动画文字淡入淡出
- 12. 优化淡入淡出框动画
- 13. UIImageView在动画之间淡入淡出
- 14. Jquery淡入淡出动画问题
- 15. 禁用淡入淡出动画
- 16. CSS交叉淡入淡出动画
- 17. TextView动画 - 淡入,等待,淡出
- 18. 淡入淡出文字动画
- 19. 淡入淡出
- 20. 淡入淡出
- 21. 淡入淡出UILabel,改变文字,淡入淡出:只有淡入淡出
- 22. jQuery - 淡入淡出滚动/淡入淡出“scrollstop”
- 23. jQuery淡入。淡入淡出div和h1
- 24. JQuery - IE6 - 如何同时淡入淡出和淡入淡出?
- 25. Superscrollorama淡入/淡出滚动
- 26. 淡入和淡出粒子
- 27. 淡入和淡出GUI.Box
- 28. C#和mp3淡入/淡出
- 29. 淡入淡出而不淡出
- 30. 简单的淡入淡出淡出div
我使用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