Detect when WPF control moves relative to its parent

I know how to find the control location relative to my parent using the TransformToAncestor method and even determine if the control is visible to the user based on this transformation.

Now I need to detect changes in the location of management. Let now ignore effects and visual transformations so that everything is simple. All I need is to monitor changes to Visual.VisualOffset . This is not a dependency property, and there is no related change event.

Visual.VisualOffset seems to be updated only during the arrangement phase. Perhaps the UIElement.LayoutUpdated event might provide me with the correct notification. But then this is a global event without parameters. I would have to iterate over all the controlled visual effects whenever something changes. Such an iteration should be performed up to 60 times per second whenever the user drags something.

I wonder if there is something less invasive that won't make me double-check all the visuals around the world.

Here is an example. See the LazyControl source. The method IsInViewchecks with TransformToAncestor. I need to call this method every time something changes, it depends on the method.

+4
source share
1 answer

What about overriding UIElement.OnRender ?

0
source

All Articles