Is there a difference between adding CommandBindings to a control vs using RegisterClassCommandBinding?

蓝咒 提交于 2019-12-05 11:22:23

The latter is more of a global handler, versus the former which is per instance.

Also, the RegisterClassCommandBinding cannot be unregistered, so you are stuck with it once you register. Generally, when using this it's best to call virtual methods on your control so their behavior can be changed or by-passed.

With CommandBindings you can remove any bindings that are no longer needed. This can also be done by external users of your control. So you may add a command binding that is required, but someone could easily do element.CommandBindings.Clear().

So there are differences, and each has their place. If you want it to be easily customizable, I'd go with the former.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!