在WP7循环选择器的选择器列表末尾停止循环



我的疑问是,是否有任何方法可以阻止循环选择器在到达列表末尾时循环。假设List有10个项目,可能是1,2,3,4…10,所以当你滚动到列表的末尾,即10,那么它不应该让u循环…它应该改变循环选择器的流方向。

  public void DisplayCatalog(string[] ServiceDisplayName, string[] WheelDisplayName, BitmapImage[] ServiceIcons, WidgetBean[] ServiceBeanList, WidgetBean[] WheelBeanList)
    {
        updateUI();
        DisplayNames.Clear();
        int idIndex = 0;
                for (int j = 0; j < WheelDisplayName.Length; j++)
                {
                    string disp1 = WheelDisplayName[j];
                    if (!Utils.isNullString(disp1))
                    {
                        DisplayNames.Add(new ItemList() { WidgetName = disp1, ID = (idIndex + 1) });
                        idIndex += 1;
                    }
                }
this.selectorLeft.DataSource = new ListLoopingDataSource<ItemList>() { Items = DisplayNames, selectedItem = DisplayNames[Index] };

对应的xaml:(我使用水平循环选择器)

 <loop:LoopingSelector
            x:Name="selectorLeft" VerticalAlignment="Center"  ItemSize="200,68" Height="63"
                              d:LayoutOverrides="Height" Width="450">
            <loop:LoopingSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel Background="#FF48BA1C" Height="75">
                        <TextBlock Margin="2,12,2,2" Width="Auto" TextTrimming="WordEllipsis" TextAlignment="Center" x:Name="scrollingTextBlock" 
                                   Text="{Binding WidgetName}" FontSize="26" Foreground="White" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                    </StackPanel>
                </DataTemplate>
            </loop:LoopingSelector.ItemTemplate>
        </loop:LoopingSelector>

一年来我一直在努力寻找这个问题的解决方案。今天我发现了这个。我只需要做一个改变。这就是……

this.selectorLeft.DataSource = new ListLoopingDataSource<ItemList>(WheelDisplayName.Length+1) { Items = DisplayNames, selectedItem = DisplayNames[Index] };

循环选择器只在项目总数大于WheelDisplayName+1时循环,否则将在最后一个项目结束时停止循环。

实现ILoopingSelectorDataSource。在列表的开始/结束处GetPrevious/GetNext返回null

。下载最新的工具包,注释GetNext的返回。注意,现在运行示例时,它没有显示任何next项,因此不会循环。

abstract class DataSource : ILoopingSelectorDataSource
{
    private DateTimeWrapper _selectedItem;
    public object GetNext(object relativeTo)
    {
        DateTime? next = GetRelativeTo(((DateTimeWrapper)relativeTo).DateTime, 1);
        return null;// next.HasValue ? new DateTimeWrapper(next.Value) : null;
    }
    public object GetPrevious(object relativeTo)
    {
        DateTime? next = GetRelativeTo(((DateTimeWrapper)relativeTo).DateTime, -1);
        return next.HasValue ? new DateTimeWrapper(next.Value) : null;
    }

最新更新