在wpf中滚动列表项
我想下面的图片比文本更好地描述了问题...
alt text http:// img179.imageshack.us/img179/8949/samplescrollingitems.png
这就是我所需要的。
<ListBox x:Name="NamesListBox" ItemsSource="{Binding}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel x:Name="ItemWrapPanel">
<WrapPanel.RenderTransform>
<TranslateTransform x:Name="ItemWrapPanelTransformation" X="0" />
</WrapPanel.RenderTransform>
<WrapPanel.Triggers>
<EventTrigger RoutedEvent="WrapPanel.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ItemWrapPanelTransformation" Storyboard.TargetProperty="X" To="-1000" From="{Binding ElementName=ScrollingListItemsWindow, Path=Width}" Duration="0:0:9" RepeatBehavior="100" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</WrapPanel.Triggers>
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Label Content="{Binding}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我就是这么做的。但在这里我不想为 X 值硬编码 -1000,而是想根据包裹面板的长度/项目数量来确定它。有人可以帮我解决这个问题吗?
我选择列表框的原因是项目数量可以随时增减,更适合问题。
如果您还有其他想法,也请提出来。
谢谢。
I guess the following picture depicts the problem better than texts...
alt text http://img179.imageshack.us/img179/8949/samplescrollingitems.png
That is what I need.
<ListBox x:Name="NamesListBox" ItemsSource="{Binding}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel x:Name="ItemWrapPanel">
<WrapPanel.RenderTransform>
<TranslateTransform x:Name="ItemWrapPanelTransformation" X="0" />
</WrapPanel.RenderTransform>
<WrapPanel.Triggers>
<EventTrigger RoutedEvent="WrapPanel.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ItemWrapPanelTransformation" Storyboard.TargetProperty="X" To="-1000" From="{Binding ElementName=ScrollingListItemsWindow, Path=Width}" Duration="0:0:9" RepeatBehavior="100" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</WrapPanel.Triggers>
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Label Content="{Binding}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
is what I did. But here I don't wanna hard code -1000 for the X value, rather I want to determine this based on the length of the wrap panel/number of items. Can somebody help me with this ??
Reason why I choose list box is that the number of items can increase and decrease at any time and suits the problem better.
If you have got any other idea, please suggest it too.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用转换器将 X 绑定到 WrapPanel?
转换器将获取 WrapPanel 实例作为参数,然后您可以分析其属性并根据项目的宽度或数量返回一个值。
Have you tried to bind X to the WrapPanel, while using a converter ?
The converter will get the WrapPanel instance as a parameter and you can then analyze its properties and return a value based on the width or number of items.