2011-12-22 43 views
1

我的疑問是,有什麼辦法可以在循環選擇器到達列表末尾時停止循環。假設列表有10個項目可能是1,2,3,4 ... 10,所以當滾動一次後,你到達列表的末尾,即10,那麼它不應該讓你循環..它應該改變方向循環選擇器的流程。是否有可能..停止WP7循環選擇器中的選擇器列表末尾處的循環

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> 

回答

1

我苦苦尋找,因爲每年這個問題的解決方案。今天我發現了this。我不得不做一個改變。那就是......

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

的循環選擇將僅環,如果項目總數大於WheelDisplayName + 1,如果不是將停在最後一個項目結束循環。

+0

你能否更新鏈接?這正是我正在尋找的!謝謝! – Quincy 2013-04-24 02:02:56

+0

它完成了!請檢查更新後的答案 – Apoorva 2013-05-07 04:40:34

0

實現ILoopingSelectorDataSource。在列表的開始/結束處的GetPrevious/GetNext中返回null。

例如下載最新的工具包,評論GetNext的回報。現在注意運行樣本,它不顯示任何下一個項目,因此不會循環。

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; 
    }