我有一个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,但我不知道如何解决这个问题。
我做错了什么?如何显示所有项目?
谢谢你!答案 0 :(得分: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,ComboBox,ListBox)。 您也可以编辑样式并将ScrollViwer放入样式中 (ScrollViwer中的ItemsPrensenter)