开发者

WPF: Is there something like Canvas.IsVisible(point)?

开发者 https://www.devze.com 2023-02-14 14:06 出处:网络
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 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.

WPF: Is there something like Canvas.IsVisible(point)?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消