简体   繁体   English

WPF文本框的IsInactiveSelectionHighlightEnabled属性不起作用?

[英]WPF TextBox's IsInactiveSelectionHighlightEnabled property is not work?

WPF's TextBox has a property named IsInactiveSelectionHighlightEnabled. WPF的TextBox具有一个名为IsInactiveSelectionHighlightEnabled的属性。 I set this property to true in order to make a TextBox always show selection. 我将此属性设置为true,以使TextBox始终显示选择。 However, it doesn't work in this case: 但是,在这种情况下不起作用: 在此处输入图片说明

    private void button_Click(object sender, RoutedEventArgs e) {
        textBox.Select(0, 10);
    }

I just want to see the selection after clicking the button. 我只想在单击按钮后看到选择。 But selection will not appear until I right click the TextBox. 但是,直到我右键单击文本框,选择才会出现。 Why? 为什么? Am I miss something? 我想念什么吗?

You should have the Keyboard focus on your textbox to select the text in it. 您应该将键盘焦点放在文本框中以选择其中的文本。

Add this code to your button click event before the selection. 在选择之前,将此代码添加到您的按钮click事件中。

Keyboard.Focus(textBox);  

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM