代码之家  ›  专栏  ›  技术社区  ›  driis

WP7列表框如何允许用户订购项目

  •  2
  • driis  · 技术社区  · 14 年前

    场景:使用MVVM的Windows Phone 7应用程序。我有一个列表框,它绑定到ViewModel中的项集合。此视图的主要用途是允许用户根据自己的喜好重新订购项目。

    如何在WP7中实现此功能?我希望这样做的方式是简单地允许用户将项目拖动到他想要的位置。这种姿态是否有内在的支持?(我还没找到)。

    3 回复  |  直到 14 年前
        1
  •  3
  •   AnthonyWJones    14 年前

    你可以把 Silverlight for Windows Phone Toolkit 然后使用 GestureListener 倾听 DragStarted , DragDelta DragComplete 事件。

        2
  •  1
  •   mikeesouth    14 年前

    正如AnthonyWJones所说,GesureListener可能正是你想要的。我只想补充一点,您可以对列表使用FluidMoveBehavior,以便在项目顺序更改时项目能够顺利地设置动画。在我看来,它提供了一个更好的用户体验。

    流体移动行为很简单,只需“插入”到您现有的列表中,如下所示:

    <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
  •  1
  •   Omar Shahine    13 年前

    这个解决方案非常有效

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

    这是一个控件,你只需把它放到你的应用程序中,你就可以简单地启用拖动手柄并在列表框中移动项目。