关注代码:
XAML:
<Window x:Class="Wpf_Notice.MostrarAviso"
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"
xmlns:local="clr-namespace:Wpf_Notice"
mc:Ignorable="d"
Title="Notice Show" Height="300" Width="300" WindowStyle="None" ShowInTaskbar="False" ResizeMode="NoResize" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<!--...-->
</StackPanel>
<Canvas Background="Black" >
<Canvas Canvas.Bottom="0" ClipToBounds="True" Name="canMain" Background="Red" Height="97" Width="300">
<TextBlock FontSize="70" Name="tbmarquee" Height="74" FontFamily="Arial Black" Foreground="White" Canvas.Top="10"></TextBlock>
</Canvas>
</Canvas>
</Grid>
</Window>
C#:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
canMain.Width = ActualWidth;
tbmarquee.Text = "Donald Trump announced on Friday a new package of measures against North Korea...";
UpdateLayout();
DoubleAnimation doubleAnimation = new DoubleAnimation
{
From = -tbmarquee.ActualWidth,
To = canMain.ActualWidth,
RepeatBehavior = new RepeatBehavior(2),
Duration = TimeSpan.FromSeconds(10)
};
tbmarquee.BeginAnimation(Canvas.RightProperty, doubleAnimation);
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None;
Topmost = true;
}
上面的代码显示了一个从右到左的新闻,使用“DoubleAnimation”类,在传递了2个新闻RepeatBehavior = new RepeatBehavior (2)
后,调用一个隐藏新闻的函数。
如何在传递2个新闻项目后调用函数?
任何解决方案?