选择一个项目两次或更多次 [英] Select an item two or more times

查看:110
本文介绍了选择一个项目两次或更多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有DataContext的列表框.当我选择一个项目时,便无法再次选择它.当有许多对象时,这不是问题,但是有时,售后服务会给我返回一个仅包含一个元素的列表,并且如果用户选择了该元素并且希望再次选择它,则他将无法执行该操作.任何人都知道如何解决这个问题

I have a Listbox with its DataContext. When I select an item, I can't select the same again. This is not a problem when there are many objects, but sometimes, a post-service return me a list with only one element, and if the user select the element and he wants select it again, he will not can do it. Anyone knows how to resolve this problem

无论如何,谢谢!

推荐答案

尝试一下,它对我有用..:)

Try this, it works for me.. :)

  public void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  {
        ListBox listBox = sender as ListBox;

        if (listBox != null && listBox.SelectedItem != null)
        {
            // do work
        }

        listBox.SelectedIndex = -1;
  }

这篇关于选择一个项目两次或更多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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