选择组合框的文本 [英] Select ComboBox Text

查看:134
本文介绍了选择组合框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ComboBox声明如下:

I have a ComboBox declared as follows:

<ComboBox Name="txtUserName" IsEditable="True" />



我要选择对焦点组合框的文本字段,但我想不出该怎么办这个。目前,当组合框专注于编程(通过txtUserName.Focus()),它允许用户通过不同的项目之间滚动,但需要额外的点击来突出显示文本字段中。

I want to select the ComboBox's text field on focus, but I can't figure out how to do this. Currently, when the ComboBox is focused on programmatically (through "txtUserName.Focus()"), it allows the user to scroll through the different items, but requires an additional click to highlight the text field.

有什么想法?

推荐答案

我用的解决方案是增加下面的代码窗口的加载事件:

The solution I used was to add the following code to the window's loaded event:

var textBox = (txtUserName.Template.FindName("PART_EditableTextBox", txtUserName) as TextBox);
if (textBox != null)
{
      textBox.Focus();
      textBox.SelectionStart = textBox.Text.Length;
 }



该解决方案从这里建议的一个答案来了:的How到注重添加到WPF 可编辑ComboBox

The solution came from one of the suggested answers here: How to add a focus to an editable ComboBox in WPF

这篇关于选择组合框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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