Should I use AdornerLayer to avoid clipping my adorner off screen?

I am writing WPF code featuring Adorners. I am using Josh Smith UIElementAdorner.cs (found in a project on the Infragistic Blog ). I love the ad text. I need to carefully place my dealer so that he does not pinch the screen.

What's the best way to find out if I'm going to clip?

I use the following code to create and host my advertiser. I have a strange feeling that, based on whether I will clip on AdornerLayer , is not the best option.

var infoBubble = new InfoBubble {InformationText = @"I like cheese."};
var adornedElementRect = new Rect(Target.DesiredSize);
var layer = AdornerLayer.GetAdornerLayer(Target);

var adorner = new UiElementAdorner<Control>(Target) { Child = infoBubble };
adorner.Measure(new Size(layer.ActualWidth, layer.ActualHeight));

var adornerRect = new Rect(adorner.DesiredSize);
var top = -1*(adornerRect.Height);
var left = adornedElementRect.Width/2;

// Using layer to judge where to place the adorner
var upperLeftPoint = Target.TranslatePoint(new Point(left, top), layer);
var lowerRightPoint = Target.TranslatePoint(new Point(left + adornerRect.Width, 
    top + adornerRect.Height), layer);

if (upperLeftPoint.Y < 0) top -= upperLeftPoint.Y; // shift down by Y
if (lowerRightPoint.X > layer.ActualWidth) 
    left  -= (lowerRightPoint.X - layer.ActualWidth); // shift left

, TargetedTriggerAction, , , ( Blend), . , .

+3
1

, , .

GetAdornerLayer . , AdornerDecorator, . AdornerDecorator ClipToBounds = "True" ( , , ).

, , AdorneLayer, , - , . (, ClipToBounds False AdornerDecorator , Window), .

+2

Source: https://habr.com/ru/post/1757909/


All Articles