How to detect that a control is being moved?

Mohamed picture Mohamed · May 10, 2011 · Viewed 7.9k times · Source

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.

Answer

Michal Ciechan picture Michal Ciechan · May 10, 2011

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.