WP7 ListBox how to allow user to order items

2020-06-27 08:02发布

Scenario: Windows Phone 7 application using MVVM. I have a ListBox that is bound to a collection of items from my ViewModel. The main usage of this view is to allow the user to re-order the items to his liking.

How do I implement this in WP7 ? The way I would like to do this would be to simply allow the user to drag items to the position he wants. Is there any built-in support for such a gesture ? (I haven't been able to find any).

3条回答
不美不萌又怎样
2楼-- · 2020-06-27 08:06

As stated by AnthonyWJones the GesureListener is probably what you are looking for. I just wanted to add that you can use a FluidMoveBehavior for the list in order for the items to animate smoothly when the item order changes. In my opinion it gives a much improved user experience.

A fluid move behavior is simple enough to just "plug in" to your existing list, like this:

<Style TargetType="ListBox" x:Key="FluidListBox">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel>
                    <i:Interaction.Behaviors>
                        <ei:FluidMoveBehavior AppliesTo="Children" Tag="DataContext">
                            <ei:FluidMoveBehavior.EaseY>
                                <BackEase EasingMode="EaseInOut" Amplitude="0.5"/>
                            </ei:FluidMoveBehavior.EaseY>
                            <ei:FluidMoveBehavior.EaseX>
                                <BackEase EasingMode="EaseInOut" Amplitude="0.5"/>
                            </ei:FluidMoveBehavior.EaseX>
                        </ei:FluidMoveBehavior>
                    </i:Interaction.Behaviors>
                </StackPanel>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>
查看更多
手持菜刀,她持情操
3楼-- · 2020-06-27 08:28

You could include in your project the Silverlight for Windows Phone Toolkit and then use the GestureListener to listen for DragStarted, DragDelta and DragComplete events.

查看更多
小情绪 Triste *
4楼-- · 2020-06-27 08:28

This solution works really well

http://blogs.msdn.com/b/jasongin/archive/2011/01/03/wp7-reorderlistbox-improvements-rearrange-animations-and-more.aspx

It's a control you just drop into your app and you can simply enable drag handles and move around items in a ListBox.

查看更多
登录 后发表回答