在WPF和ComboBox控件中,如何获取突出显示的索引? [英] in WPF and for ComboBox control , how to get highlighted Index ?

查看:117
本文介绍了在WPF和ComboBox控件中,如何获取突出显示的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在WPF中有一个ComboBox,
我需要获取突出显示的项目的索引
未选择项目和未选择索引

例如:

Hello,

I have a ComboBox in WPF ,
I need to get the index of highlighted Item
Not Selected Item and not Selected Index

for example:

int a = MyComboBox.SelectedIndex;



但我不需要这个,我需要突出显示项目的索引.

我的意思是我要使用键盘(上,下)和鼠标在该项目上滚动的索引.

谢谢.



but I don''t need this, I need the Index of Highlighted Item.

I mean I want the Index of the Item which I am scrolling on that with keyboard (Up , Down) and Mouse.

Thank you.

推荐答案

ComboBoxItem
MouseMove添加代码


Add code to MouseMove of ComboBoxItem

or

<ComboBoxItem MouseMove="ComboBoxItem_MouseMove">Item 1</ComboBoxItem>





Private Sub ComboBoxItem_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs)
 'ComboBox1.Items.IndexOf(DirectCast(sender, ComboBoxItem)
End Sub


这是获取该项目索引的方法.


您可以使用它在ComboBox的MouseMove和KeyDown上突出显示项目.


This is how you can get index of that item.


You can use this to get highlighted item on MouseMove and KeyDown of ComboBox.

Private Function GetHighlightedItem(ByVal cbox As ComboBox) As Integer
  For Each item As ComboBoxItem In cbox.Items
    If item.IsHighlighted Then
      Return ComboBox1.Items.IndexOf(item)
    End If
  Next
  Return -1
End Function


希望,此线程 [
Hopefully, this thread[^] will give you a solution.


这篇关于在WPF和ComboBox控件中,如何获取突出显示的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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