如何检测控件正在移动?
假设我有一个带有自定义用户控件的窗口,并且用户控件内部有一个文本框。当我拖动窗口时,文本框如何检测到它正在移动?
我尝试搜索其 RenderTransform 属性,当“Freezable 对象或其对象之一发生更改”时,会触发 Change 事件。没有什么定论..
编辑:
就我而言,我没有看到窗口,我看到的只是用户控件,我不能再更高了。
Suppose I have a window with a custom UserControl, and the UserControl has a textbox inside. When I drag the window around, how can the TextBox detect that it is being moved ?
I tried to search around its RenderTransform property, there is that Change event that gets fired when "the Freezable object or one of its objects change". Nothing conclusive..
Edit :
In my case, I don't see the window, all I see is the UserControl and I can't go any higher.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要订阅 Window 事件,因为您的文本框实际上并未移动(它很可能位于与窗口相关的相同位置),因此您可以订阅 Window.LocationChanged 事件以获取通知当窗口移动时。
但如果您的控件没有绝对位置,那么您将需要解析 Window.SizeChanged ,它将告诉您用户何时调整了窗口大小,但它是一个离散的最终事件,而不是一个 in - 进展事件。
You will need to subscribe to the Window events, as your textbox is not actually moving (its most likely in the same position relevant to the window) so you can subscribe to the
Window.LocationChanged
event to be notified when the window is moved.But Also If your control does not have an absolute position then you will need to parse
Window.SizeChanged
which will tell you when the user has resized the window, but it’s a discrete final event as opposed to an in-progress event.尝试订阅 UserControl 的 LayoutUpdated 事件。
Try subscribing to the LayoutUpdated event of the UserControl.