如何在WPF窗口中取消选择所有内容? [英] How do I deselect everything in a WPF window?

查看:69
本文介绍了如何在WPF窗口中取消选择所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道是否有办法取消选择WPF窗口上的所有内容?我已经看到一些应用程序做了类似的事情,通常是在按下转义键时。它似乎做的是将窗口恢复到首次加载时的状态,然后用户点击任何东西或选项卡到窗口上的控件。



我尝试了什么:



没有什么是真的,因为到目前为止我还没有找到任何看起来会做我需要的东西。



我在考虑尝试使用隐形控件并设置焦点,但这感觉就像一个完整的黑客。

Does anyone know if there is a way to deselect everything on a WPF window? I've seen some applications do something similar, often when pressing the escape key. What it appears to do is to put the window back in the state when it was first loaded, before the user clicks anything or tabs to a control on the window.

What I have tried:

Nothing really because so far I haven't found anything that looks like it will do anything I need.

I am thinking of maybe trying to have an invisible control and setting focus to that, but this feels like a complete hack.

推荐答案

这将是一个完整的黑客攻击,因为如果这个要求发生变化,你将失去对取消选择内容的控制权。



正确的解决方案是编写代码通过控件并清除选择,但需要为每个控件完成。它不是最性感的解决方案,但它是可维护和可调试的。



然后,您可以从事件处理程序或其他代码中调用此方法。
That would be a complete hack because you loose control over what gets deselected if this requirement ever changes.

The proper solution is to write the code to go through the controls and clear the selections however it needs to be done for each. It's not the sexiest solution but it's maintainable and debugable.

You can then call this method from an event handler or from some other code if required.


这篇关于如何在WPF窗口中取消选择所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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