2013-02-12 99 views
2

我有我想要显示为列表的对象的集合。所以,我用这个集合绑定了一个LongListSelector。集合中的所有项目都以列表的形式出现。接下来我想要做的事情是,当用户长时间按住一个物品时,它会弹出一个带有删除,添加和其他选项的小窗口。LongListSelector和上下文菜单

我该怎么做?我在很多地方搜索,没有发现任何关于LongListSelector和上下文菜单

+0

你可以在问题中提供一些更多细节吗?你只是在寻找一个好的ContextMenu?因为如果是这样的话,在手机工具包中有一个控件:http://phone.codeplex.com/ – Depechie 2013-02-12 14:31:10

+0

我在我的应用程序中有LongListSelector,我希望当用户长按项目时,它会弹出一个类似于对话框的东西给用户从列表中删除,播放项目.....这就像在windowsphone主菜单中的应用程序菜单 – MTA 2013-02-12 14:41:25

+0

好的...所以我以前的建议是你在找什么!这里是一个很好的教程:http://windowsphonegeek.com/articles/wp7-contextmenu-in-depth--part1-key-concepts-and-api – Depechie 2013-02-13 10:35:48

回答

3

如果你想要一个上下文菜单...看看0123M中的ContextMenu控件。

那么对于如何添加一个例子,看看该工具包本身,但更具体的你的问题,你可以看看类似的question here...

总之,你只需要添加上下文菜单中的XAML您longlistselector的每个数据项

-1

简单的代码来把上下文菜单上longListSelector:

<phone:LongListSelector x:Name="lls" LayoutMode="List" Margin="0,150,0,0"> 
    <phone:LongListSelector.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal" Margin="12,2,0,4" Height="105" Width="432"> 
       <Border BorderThickness="1" Width="99" Height="99" BorderBrush="#FFFFC700" Background="#FFFFC700"/> 
       <StackPanel Width="311" Margin="8,-7,0,0"> 
        <toolkit:ContextMenuService.ContextMenu> 
         <toolkit:ContextMenu IsZoomEnabled="True"> 
          <toolkit:MenuItem Header="Delete" Click="Delete_Click"/> 
         </toolkit:ContextMenu> 
        </toolkit:ContextMenuService.ContextMenu> 
        <TextBlock Text="{Binding data}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
        <TextBlock Text="{Binding resume}" TextWrapping="NoWrap" Margin="12,-6,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
       </StackPanel> 
      </StackPanel> 

     </DataTemplate> 
    </phone:LongListSelector.ItemTemplate> 
</phone:LongListSelector> 

你有你把ContextMenuService.ContextMenu关注。如果你把它从StackPanel中拿出来(在我的例子中),这是行不通的。

+0

为什么是负面的? – Dherik 2016-06-16 11:24:56