如何在 WPF 中获取 ComboBox.SelectedText [英] How to get ComboBox.SelectedText in WPF

查看:39
本文介绍了如何在 WPF 中获取 ComboBox.SelectedText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF ComboBox 中没有 SelectedText 属性.

In WPF ComboBox does not have SelectedText property.

有没有办法实现与 WPF 中 TextBox SelectedText 相同的功能

Is there a way to achieve the same functionality as TextBox SelectedText has in WPF

推荐答案

您可以通过以下方式访问 ComboBox 的 TextBox:

You can get access to the ComboBox's TextBox by using:

var edit = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);

然后您可以访问该 TextBox 的 SelectedText 属性:

Then you can access the SelectedText property of that TextBox:

var selectedText = edit.SelectedText;

这篇关于如何在 WPF 中获取 ComboBox.SelectedText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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