问题描述
我想下面的图片比文字更好地描述了问题...
I guess the following picture depicts the problem better than texts...
替代文字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,而是我想根据包装面板的长度/项目数确定此值.有人可以帮我吗?
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.
谢谢.
推荐答案
在使用转换器时,是否尝试将X绑定到WrapPanel?
Have you tried to bind X to the WrapPanel, while using a converter ?
转换器将获取WrapPanel实例作为参数,然后您可以分析其属性并根据项目的宽度或数量返回一个值.
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.
这篇关于在WPF中滚动列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!