<Canvas x:Name="c1" >
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard x:Name="animation" RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="tbnews" Storyboard.TargetProperty="(Canvas.Left)" From="100" To="-200" Duration="0:0:20">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<TextBlock x:Name="tbnews" Text="{Binding txtnews}" FontSize="14" HorizontalAlignment="Left" Foreground="Yellow" >
<TextBlock.Effect>
<DropShadowEffect Color="White"
BlurRadius="30" Opacity="1" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</Canvas>
<TextBlock Text="{Binding addtime}" HorizontalAlignment="Left" FontSize="10" Foreground="Yellow">
<TextBlock.Effect>
<DropShadowEffect Color="White"
BlurRadius="30" Opacity="1" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
第二种方法
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="LayoutNews" >
<Grid.Clip>
<RectangleGeometry x:Name="rg" Rect="0,150,100,100" />
</Grid.Clip>
<Canvas Width="150" x:Name="canvasNews" Background="White">
<StackPanel>
<TextBlock x:Name="tb" Margin="0,5,0,0" TextWrapping="Wrap" Width="150" Text="{Binding txtnews}" Foreground="Yellow">
<TextBlock.Effect>
<DropShadowEffect Color="White"
BlurRadius="30" Opacity="1" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
<TextBlock Text="{Binding addtime}" HorizontalAlignment="Left" FontSize="10" Foreground="Yellow">
<TextBlock.Effect>
<DropShadowEffect Color="White"
BlurRadius="30" Opacity="1" ShadowDepth="0"/>
</TextBlock.Effect>
</TextBlock>
</StackPanel>
</Canvas>
<Rectangle Width="300" Height="1" Fill="#3E2A0C"></Rectangle>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
int top = 0;
public MainPage()
{
// 为初始化变量所必需
InitializeComponent();
AddItems();
displaynews();
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 100);
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
top = top - 10;
Canvas canvasNews = LayoutNews.FindName("canvasNews") as Canvas;
canvasNews.Margin = new Thickness(0, top, 0, 0);
}