Exemple #1
0
		public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan? visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback removedCallback) {
			if (adornment == null)
				throw new ArgumentNullException(nameof(adornment));
			if (visualSpan == null && behavior == AdornmentPositioningBehavior.TextRelative)
				throw new ArgumentNullException(nameof(visualSpan));
			if ((uint)behavior > (uint)AdornmentPositioningBehavior.TextRelative)
				throw new ArgumentOutOfRangeException(nameof(behavior));
			if (layerKind != LayerKind.Normal) {
				if (behavior != AdornmentPositioningBehavior.OwnerControlled)
					throw new ArgumentOutOfRangeException(nameof(behavior), "Special layers must use AdornmentPositioningBehavior.OwnerControlled");
				if (visualSpan != null)
					throw new ArgumentOutOfRangeException(nameof(visualSpan), "Special layers must use a null visual span");
			}
			bool canAdd = visualSpan == null || TextView.TextViewLines.IntersectsBufferSpan(visualSpan.Value);
			if (canAdd) {
				var layerElem = new AdornmentLayerElement(behavior, visualSpan, tag, adornment, removedCallback);
				layerElem.OnLayoutChanged(TextView.TextSnapshot);
				Children.Add(layerElem.Adornment);
				adornmentLayerElements.Add(layerElem);
			}
			return canAdd;
		}
Exemple #2
0
        public bool AddAdornment(AdornmentPositioningBehavior behavior, SnapshotSpan?visualSpan, object tag, UIElement adornment, AdornmentRemovedCallback?removedCallback)
        {
            if (adornment is null)
            {
                throw new ArgumentNullException(nameof(adornment));
            }
            if (visualSpan is null && behavior == AdornmentPositioningBehavior.TextRelative)
            {
                throw new ArgumentNullException(nameof(visualSpan));
            }
            if ((uint)behavior > (uint)AdornmentPositioningBehavior.TextRelative)
            {
                throw new ArgumentOutOfRangeException(nameof(behavior));
            }
            if (layerKind != LayerKind.Normal)
            {
                if (behavior != AdornmentPositioningBehavior.OwnerControlled)
                {
                    throw new ArgumentOutOfRangeException(nameof(behavior), "Special layers must use AdornmentPositioningBehavior.OwnerControlled");
                }
                if (visualSpan is not null)
                {
                    throw new ArgumentOutOfRangeException(nameof(visualSpan), "Special layers must use a null visual span");
                }
            }
            bool canAdd = visualSpan is null || TextView.TextViewLines.IntersectsBufferSpan(visualSpan.Value);

            if (canAdd)
            {
                var layerElem = new AdornmentLayerElement(behavior, visualSpan, tag, adornment, removedCallback);
                layerElem.OnLayoutChanged(TextView.TextSnapshot);
                Children.Add(layerElem.Adornment);
                adornmentLayerElements.Add(layerElem);
            }
            return(canAdd);
        }