在 WPF 文本框上调用 Select() 没有任何作用 [英] Calling Select() on WPF text box doesn't do anything

查看:50
本文介绍了在 WPF 文本框上调用 Select() 没有任何作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WPF 文本框,我正在调用 Select() 方法来进行选择.不幸的是,它似乎不起作用除非我先手动选择了一些东西.有人可以建议为什么会发生这种情况吗?

I'm using a WPF TextBox, and I'm calling the Select() method to make a selection. Unfortunately, it doesn't seem to work unless I select something manually first. Can someone suggest as to why it happens?

推荐答案

当您调用 Select 方法时,您的文本框是否具有焦点?

Does your textbox have focus when you call the Select method?

除非有焦点,否则选择不会显示,但文本框获得焦点的常用方法是单击它...取消选择文本.这种行为可能给人一种它不起作用的印象.

The selection will not show unless it has focus, but the common way for the textbox to get focus is by clicking on it...which deselects the text. This behaviour could give the impression that it's not working.

在调用 Select() 之后(或之前)调用 TextBox.Focus() 应该可以修复它.

Calling TextBox.Focus() after (or before) calling Select() should fix it.

这篇关于在 WPF 文本框上调用 Select() 没有任何作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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