2011-04-11 36 views
0

我有一個Silverlight應用程序需要在應用程序的頁腳上滾動一些數據(如股票信息)。在努力做到這一點,我創建了以下內容:在Silverlight中創建滾動項目

<UserControl.Resources> 
    <Storyboard x:Name="myListStoryboard" BeginTime="0:0:0" Completed="myListStoryboard_Completed"> 
     <DoubleAnimation x:Name="myListAnimation" Duration="0:0:30" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="myItemsControl" /> 
    </Storyboard> 
</UserControl.Resources> 


<Border x:Name="infoListBorder" Grid.Row="1" Height="40" HorizontalAlignment="Stretch" BorderThickness="1,1,0,0" Background="Silver"> 
    <Grid> 
    <ItemsControl x:Name="myItemsControl" HorizontalAlignment="Right" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
     <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal"></StackPanel> 
     </ItemsPanelTemplate>       
     </ItemsControl.ItemsPanel> 
     <ItemsControl.RenderTransform> 
     <CompositeTransform/> 
     </ItemsControl.RenderTransform> 
    </ItemsControl> 
    </Grid> 
</Border> 

我在我的代碼綁定字符串元素myItemsControl的名單後面。這些元素將會是對象,我想在我的ItemsControl中使用DataTemplate。現在,我只是試圖讓文本顯示出來。我的問題是,並非所有的項目都顯示正確。它看起來好像最後一個被切斷了。我懷疑它是因爲Items控件中的UIVirtualization,但我不知道如何解決這個問題。

我在做什麼錯?我如何讓我的所有物品都能出現?

你好!

回答

1

嘗試以下

<Border x:Name="infoListBorder" Grid.Row="1" Height="40" HorizontalAlignment="Stretch"      BorderThickness="1,1,0,0" Background="Silver"> 
    <Grid> 
    <ScrollViewer> 
     <ItemsControl x:Name="myItemsControl" HorizontalAlignment="Right" > 
      <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"></StackPanel> 
      </ItemsPanelTemplate>       
      </ItemsControl.ItemsPanel> 
      <ItemsControl.RenderTransform> 
      <CompositeTransform/> 
      </ItemsControl.RenderTransform> 
     </ItemsControl> 
    </ScrollViewer> 
    </Grid> 
</Border> 

的ItemsControl沒有預設模板的ScrollViewer(DataGrid中,組合框,列表框)。 你也可以編輯樣式並將ScrollViwer放入樣式 (ScrollViwer內的ItemsPrensenter)