上下文菜单选择项wp7 [英] Context menu selected item wp7

查看:60
本文介绍了上下文菜单选择项wp7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框。每个项目都有Context菜单。如果我只是按住项目并对其进行操作,则不会选中它并且会出现错误。如果我对第一个选择项目进行了操作,那么一切正常,如何选择项目?

I have a Listbox. Each item has Context menu.IfI simply hold on item and do work with it, it not selected and I get error.If I for the first select item and than do work, all is ok.How I can select item on hold gesture?

              <DataTemplate>
                <Grid Margin="0,5">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                  </Grid.ColumnDefinitions>
                  <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu IsEnabled="{Binding uid, Converter={StaticResource CanDelete}}"  IsZoomEnabled="True" x:Name="databoundMenu">
                      <toolkit:MenuItem Header="Удалить"  Click="deleteComment"/>
                    </toolkit:ContextMenu>
                  </toolkit:ContextMenuService.ContextMenu>
.....
                </Grid>
              </DataTemplate>

c#

var it = this.comm_box.SelectedItem as Comments;


推荐答案

ContextMenuService出于明显的原因,不会调用SelectionChanged事件,并且不设置SelectedItem,因为这将意味着带有诸如删除之类的选项的ContextMenus会出错。

The ContextMenuService for obvious reasons, doesn't invoke the SelectionChanged event, and doesn't set the SelectedItem, since this would mean that ContextMenus with options such as "Remove" would bug out.

想什么/ em>的问题是您在进行工作之前没有检查SelectedItem是否已真正设置。

What I think is your problem is that you're not checking if the SelectedItem is actually set, before doing the work on it.

相反,您应该验证SelectedItem是否为不为null,然后再进行任何操作。

Instead you should validate that the SelectedItem is not null, before doing any work with it.

这篇关于上下文菜单选择项wp7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆