在组合框,我怎么确定(不选择的项目)中突出显示的项目? [英] In a combobox, how do I determine the highlighted item (not selected item)?

查看:134
本文介绍了在组合框,我怎么确定(不选择的项目)中突出显示的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,公平的警告:我用C#和WPF一个完整的新手

First, fair warning: I am a complete newbie with C# and WPF.

我有一个组合框(可编辑,可搜索),我希望能到。拦截删除键,然后从列表中删除当前突出显示的项目。我在寻找的行为是像微软的Outlook中的电子邮件地址输入时,。当你给几个字符,显示潜在匹配的下拉列表。如果你移动到其中一个(使用箭头键),并按下删除,该条目被永久删除。我想这样做,在组合框的条目

I have a combobox (editable, searchable) and I would like to be able to intercept the Delete key and remove the currently highlighted item from the list. The behavior I'm looking for is like that of MS Outlook when entering in email addresses. When you give a few characters, a dropdown list of potential matches is displayed. If you move to one of these (with the arrow keys) and hit Delete, that entry is permanently removed. I want to do that with an entry in the combobox.

下面是XAML(简体):

Here is the XAML (simplified):


<ComboBox x:Name="Directory"
    KeyUp="Directory_KeyUp"
    IsTextSearchEnabled="True"
    IsEditable="True"
    Text="{Binding Path=CurrentDirectory, Mode=TwoWay}"
    ItemsSource="{Binding Source={x:Static self:Properties.Settings.Default}, 
        Path=DirectoryList, Mode=TwoWay}" />

的处理程序是:


private void Directory_KeyUp(object sender, KeyEventArgs e)
{
    ComboBox box = sender as ComboBox;
    if (box.IsDropDownOpen &&  (e.Key == Key.Delete))
    {
        TrimCombobox("DirectoryList", box.HighlightedItem);  // won't compile!
    }
}

在使用调试器,我可以看到 box.HighlightedItem 有我想要的价值,但是当我试图把该代码,它失败,编译:

When using the debugger, I can see box.HighlightedItem has the value I want but when I try and put in that code, it fails to compile with:

System.Windows.Controls.ComboBox'不包含定义'HighlightedItem...

所以:如何我做访问的价值?请记住,该项目具有不是被选中。它只是强调当鼠标悬停在

So: how do I access that value? Keep in mind that the item has not been selected. It is merely highlighted as the mouse hovers over it.

感谢您的帮助。

下面是截图显示调试器的显示。我徘徊在盒子,并显示一行摘要的时候,我再上空盘旋+字符扩大到该图像:

Here is a screenshot showing the debugger's display. I hovered over "box" and when the one-line summary was displayed, I then hovered over the + char to expand to this image:

推荐答案

突出显示的项目属性是一个非公开的成员,所以你不能从另一个类调用它。

The Highlighted Item property is a Non-Public member, so you can't call it from another class.

我相信你需要使用反射来获得在非公共成员。下面是一个SO张贴关于这个问题: http://stackoverflow.com/questions/769634/access-非公有制会员-reflectionattribute

I believe you need to use Reflection to get at Non-Public members. Here's a SO post on the subject: http://stackoverflow.com/questions/769634/access-non-public-members-reflectionattribute

这篇关于在组合框,我怎么确定(不选择的项目)中突出显示的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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