wpf - 自动完成框不会在鼠标按下时更新

发布于 2024-10-12 21:15:12 字数 369 浏览 5 评论 0原文

我有一个可以使用的自动完成框,但有一点奇怪,我希望得到帮助。在弹出窗口中选择一个项目时,使用键盘向下箭头,然后使用 Enter 键或鼠标选择它,该项目将被选中并更新到自动完成框中。但是,如果不是向下箭头指向该项目,而是将鼠标悬停在该项目上并用鼠标选择它,则所选项目设置正确,但自动完成框不会随所选项目更新。

也就是说,向下箭头并选择一个项目,自动完成框会反映所选项目,而仅将鼠标悬停在该项目上并选择该项目意味着自动完成框不会反映选择 - 相反,它会显示用户在框中输入的内容;请注意,支持属性知道所选项目,因此它确实可以以任何方式工作,只是它不会反映在文本框中。

任何帮助表示赞赏。 谢谢,

我应该补充一点,OnSelectedItemChanged 似乎没有被调用......

I have an autocompletebox that works but for one oddity I was hoping for help with. When selecting an item in the popup, using the keyboard to arrow down and then selecting it using either the enter key or with the mouse, the item is selected and updated into the autocompletebox. However, if one instead of arrowing down to the item simply hovers over it instead and select it with the mouse, the selecteditem is set correctly but the autocompletebox doesn't get updated with the selecteditem.

That is, arrow down and select an item and the autocompletebox reflects the selected item whereas just hovering over and selecting the item means the autocompletebox does not reflect the selection - instead it shows what the user typed into the box; note that the backing property is aware of the selected item so it does work either way, only it's not reflected in the textbox.

Any help is appreciated.
Thanks

I should add that it is OnSelectedItemChanged that doesn't seem to get called...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-10-19 21:15:12

此问题的解释如下:http://www.siimviikman。 com/2012/05/30/wpf-autocompleteboxfiltering-similar-items/

正如文章末尾所述,用户无法浏览项目(使用箭头键 + 按 TAB)。这就是为什么我不能使用他们的解决方案。

在 WPF Toolkit 源代码(UpdateTextCompletion 方法)中,可以读到:

// Perform an exact string lookup for the text. This is a 
// design change from the original Toolkit release when the 
// IsTextCompletionEnabled property behaved just like the 
// WPF ComboBox's IsTextSearchEnabled property.
//
// This change provides the behavior that most people expect
// to find: a lookup for the value is always performed.
newSelectedItem = TryGetMatch(text, _view, AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive));

因此,我简单地修补了 WPF Toolkit 并注释掉了 OnAdapterSelectionComplete 和 OnAdapterSelectionCanceled 中对 UpdateTextCompletion 方法的调用。

由于我不使用文本完成,因此此修复似乎工作正常。

This issue is explained here: http://www.siimviikman.com/2012/05/30/wpf-autocompleteboxfiltering-similar-items/

As precised in the end of the article, the user cannot navigate through items (with arrow keys + hit TAB). That is why I could not use their solution.

In the WPF Toolkit source code (UpdateTextCompletion method), one can read:

// Perform an exact string lookup for the text. This is a 
// design change from the original Toolkit release when the 
// IsTextCompletionEnabled property behaved just like the 
// WPF ComboBox's IsTextSearchEnabled property.
//
// This change provides the behavior that most people expect
// to find: a lookup for the value is always performed.
newSelectedItem = TryGetMatch(text, _view, AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive));

So I simply patched the WPF Toolkit and commented out the calls to UpdateTextCompletion method, both in OnAdapterSelectionComplete and OnAdapterSelectionCanceled.

As I don't use text completion, this fix seems to work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文