如何确定导致 WPF TextBox 的 GotFocus 事件的原因 - 鼠标单击或 TAB 键?
如何确定导致 WPF TextBox 的 GotFocus 事件的原因 - 鼠标单击或 TAB 键? 如果使用 TAB 键设置焦点,我需要更改边框颜色;如果使用鼠标单击设置焦点,则需要保留边框的标准颜色。因此,我需要从事件参数中提取导致事件的原因,或者(更好)编写触发器将其放入 TextBox 样式。
How to determine what caused GotFocus event of WPF TextBox - mouse click or TAB key?
I need to change border color if focus was set with TAB key and leave border's standart color if focus was set with mouse click. So I need to extract from event args what caused an event, or (better) write trigger to put it into TextBox style.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 OnKeyUp 和 OnMouseUp 事件而不是 GotFocus 事件来确定这一点。在 OnKeyUp 中,您需要测试(请参阅 Eventargs)是否按下了 Tab 键。
I would suggest using the OnKeyUp and OnMouseUp events rather than the GotFocus event to determine this. In OnKeyUp, you will need to test (see Eventargs) that it was the Tab key that was pressed.
您能否扩展 WPF TextBox,然后将其用于所有文本框?然后,您可以使用一些覆盖的事件来确定您的注意力集中方式,或进行边界更改。
Could you extend the WPF TextBox and then use that for all your text boxes instead? Then you could have some overridden events to determine how you were focused, or to do the border changes.