2010-01-13 41 views
2

我正在Silverlight自動收報機應用程序上工作,類似於5個鏈接的東西將會顯示出來,並且它們將像一個自動收報機(從右到左)一樣移動。 我能夠解析I/P的XML文件,也獲得標題和相應的網址,那些在頁面中正常出現,也像移動股票一樣移動,但循環效應丟失。意味着連續的鏈接流不正確。在自動收銀機中的循環效應

<Grid x:Name="LayoutRoot"> 
    <StackPanel x:Name="mystackpanel" Grid.Column="1" Orientation="Vertical"> 
     <Canvas> 
      <Canvas.Resources> 
       <Storyboard x:Name="sb"> 
        <DoubleAnimation x:Name="da" BeginTime="00:00:05" 
       Storyboard.TargetName="LinkList" 
       Storyboard.TargetProperty="(Canvas.Left)" 
       From="0" To="-500" Duration="0:0:5" RepeatBehavior="Forever"/> 

       </Storyboard> 
      </Canvas.Resources> 
      <ListBox x:Name="LinkList" 
        BorderThickness="0" 
        Opacity="0.5" 
        HorizontalAlignment="Left" 
        > 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel x:Name="panel" Orientation="Horizontal" HorizontalAlignment="Left"/> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <HyperlinkButton x:Name="mylink" 
             Foreground="Black" 
             FontSize="10" 
             FontWeight="Bold" 
             ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
             Tag="{Binding}" 
             Content="{Binding Path=Title}" 
             NavigateUri="{Binding Path=URi}" 
             IsTabStop="False"/> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

</Canvas> 

</StackPanel> 

    </Grid> 

如何獲得循環效果?

回答

0

以下是獲取所需效果的最簡單方法。

  • 將雙動畫中的From設置爲外部的寬度StackPanel。這樣你的網址就從最右邊開始。
  • 確保To值至少爲要滾動的內容的整個寬度的負值。
  • RectangleGeometry添加到您的外部StackPanel,它的起點爲0,0並且具有您的StackPanel的寬度和高度。
  • 調整Duration以獲得合理的像素/秒速率(您希望隨着更多內容出現,恆速不會增加)。