WPF: Is there something like Canvas.IsVisible(point)?
Is there something like Canvas.IsVisible(point)
?
I have a Canvas
inside a Sc开发者_Go百科rollViewer
. Inside the canvas I have a custom control that should be always in the visible part of the Canvas.
Is there a way to identify the Canvas visible rectangle or point?
I created an extension method that checks whether an element is fully visible inside a container:
public static bool IsUserVisible(this FrameworkElement element, FrameworkElement container)
{
if (!element.IsVisible)
return false;
var bounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
var rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
return rect.Contains(bounds);
}
In your case you can try using it something like this:
myUserControl.IsUserVisible(scrollViewerWithMyCanvas);
You can use ZOrder property of canvas and always put yours control on the top of canvas
精彩评论