开发者

Creating a Looping Listbox

Hi I want to create a looping listbox so that the last item's next item is the very first item and vice versa - creating a listbox that doesn't have a top or a bottom.

I know there is a LoopingSelector in the WP7 toolkit but it doesn't quite do what I want since it fades in/out peripheral items and you have a 'selected' item that is always in the middle.

I looked at the LinkedList collection but it doesn't seem开发者_如何学编程 to support looping: "The LinkedList(Of T) class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state."

Does anyone know a solution for what I'm looking for or would I need to develop a hybrid of the current Listbox and the toolkit's LoopingSelector?

Many thanx!


Take a look at Petzold's article on circular lists in MSDN Magazine.


I recently have a same problem as your! I use blend 4 to handle this, making my list reset to certain position at certain time, also adding a copy of a list in front and behind of the original list.

example: my list is: 1-2-3-4-5-6, I would make it 1-2-3-4-5-6-1-2-3-4-5-6-1-2-3-4-5-6 and it reset to original position every 20sec. For example: if user was on item 4 it would reset the position to item 4 but at the middle list.

I currently have my question asking here you can check out if anything help: horizontal listbox that could be infinite circle scrolling


Use Scrollviewer contains listbox, put manipulationCompleted event and use ScrolltoVerticalOffset(0) to have it looping scrolling. Maybe my code would help:

 <ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="-2,567,-1,0" x:Name="imagesScrollview"
                  Opacity="1" Grid.Row="1" RenderTransformOrigin="0.5,0.5" 
                  ManipulationCompleted="imagesScrollview_ManipulationCompleted" Height="85" MouseLeftButtonDown="ScrollViewer_MouseLeftButtonDown">
        <ScrollViewer.Background>
            <ImageBrush ImageSource="/PhoneApp11;component/Images/top_friends_float.png" />
        </ScrollViewer.Background>
        <ListBox  x:Name="listBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="Auto" Height="80" Background="{x:Null}">

            <ListBox.ItemTemplate>
                <DataTemplate>

and in Manipulation event:

        private void imagesScrollview_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        ScrollViewer scrollviewer = sender as ScrollViewer;

        if (scrollviewer.HorizontalOffset > (listBox.ActualWidth - 700))
            scrollviewer.ScrollToHorizontalOffset(0);
        else if (scrollviewer.HorizontalOffset < 100)
            scrollviewer.ScrollToHorizontalOffset((listBox.ActualWidth - 487));
    }

***Notice: I allow my scrollviewer to loop in both way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜