【发布时间】:2015-03-24 21:20:03
【问题描述】:
有人可以帮帮我吗? 我想要做的是,在我的文本块上制作一个随机引用淡入淡出。 我正在尝试使用名为“FadeInThemeAnimation”的东西。 问题是我不知道如何让它无休止地工作,所以我的随机报价在设置时间后出现和消失。我已经在 xaml 中测试了十几个属性,看看会发生什么,但似乎我不知道该怎么做。目前报价出现在文本块中(没有任何淡入效果)并慢慢淡出,就是这样。请问,我该如何让它工作。我正在粘贴我拥有的一大块 xaml 代码。
<TextBlock x:Name="FamousQuoteTextBlock" Grid.Row="4" HorizontalAlignment="Stretch" Margin="5,5,5,5"
FontSize="15" TextAlignment="Justify" TextWrapping="Wrap" VerticalAlignment="Stretch"
Loaded="FamousQuoteTextBlock_Loaded"
FontFamily="Edwardian Script ITC"
DataContext="{Binding quote}"
Text="{Binding RandomQuote,Mode=TwoWay}"
/>
<StackPanel>
<StackPanel.Resources>
<Storyboard x:Name="EnterStoryboard">
<FadeInThemeAnimation Storyboard.TargetName="FamousQuoteTextBlock"/>
</Storyboard>
<Storyboard x:Name="ExitStoryboard">
<FadeOutThemeAnimation Storyboard.TargetName="FamousQuoteTextBlock"/>
</Storyboard>
</StackPanel.Resources>
</StackPanel>
我尝试使用 speedratio、duratio 等来看看会发生什么,但没有任何区别:(
我背后的 C# 代码:
private void FamousQuoteTextBlock_Loaded(object sender, RoutedEventArgs e)
{
Delay(sender, e);
}
private async void Delay(object sender, RoutedEventArgs e)
{
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(3));
generator_Tick(this, e);
DispatcherTimer generator = new DispatcherTimer();
generator.Tick += generator_Tick;
generator.Interval = TimeSpan.FromSeconds(5);
generator.Start();
}
private void generator_Tick(object sender, object e)
{
Quote quote = new Quote();
FamousQuoteTextBlock.DataContext = quote;
quote.GenerateQuote();
}
【问题讨论】:
-
在情节提要中,您可以使用以不透明度为目标的 DoubleAnimation。也可以设置一个行为以无限运行并反转动画(意味着淡入将导致淡出)。
标签: c# xaml windows-phone-8.1 windows-8.1