Example #1
0
 public void Update(TimeSpan lifetime, Animation animation, Thickness margin, Size size,
                    HorizontalPlacement horizontalPlacement, VerticalPlacement verticalPlacement)
 {
     lock (_lock)
     {
         Parallel.Invoke(
             () =>
         {
             Settings.Default.Lifetime            = lifetime;
             Settings.Default.Animation           = animation;
             Settings.Default.Margin              = margin;
             Settings.Default.Size                = size;
             Settings.Default.HorizontalPlacement = horizontalPlacement;
             Settings.Default.VerticalPlacement   = verticalPlacement;
             Settings.Default.Save();
         },
             () =>
         {
             _lifetimeCache            = lifetime;
             _animationCache           = animation;
             _marginCache              = margin;
             _sizeCache                = size;
             _horizontalPlacementCache = horizontalPlacement;
             _verticalPlacementCache   = verticalPlacement;
         });
     }
 }
        private static double[] GetHorizontalOffsets(HorizontalPlacement horizontalPlacement, double popupWidth, double targetWidth, double offsetWidth)
        {
            var horizontalOffsets = Enumerable.Repeat <double>(offsetWidth, 2).ToArray();

            switch (horizontalPlacement)
            {
            case HorizontalPlacement.Left:
                horizontalOffsets[0] += -popupWidth;
                horizontalOffsets[1] += targetWidth;
                break;

            case HorizontalPlacement.Center:
                horizontalOffsets[0] += targetWidth / 2 - popupWidth / 2;
                horizontalOffsets[1]  = horizontalOffsets[0];
                break;

            case HorizontalPlacement.Right:
                horizontalOffsets[0] += targetWidth;
                horizontalOffsets[1] += -popupWidth;
                break;

            default:
                throw new Exception("Invalid Vertical Placement");
            }

            return(horizontalOffsets);
        }
 private static bool TryParsePlacements(string arg1, string arg2, out HorizontalPlacement horizontal, out VerticalPlacement vertical)
 {
     vertical = default(VerticalPlacement);
     return((Enum.TryParse(arg1, ignoreCase: true, result: out horizontal) &&
             Enum.TryParse(arg2, ignoreCase: true, result: out vertical)) ||
            (Enum.TryParse(arg2, ignoreCase: true, result: out horizontal) &&
             Enum.TryParse(arg1, ignoreCase: true, result: out vertical)));
 }
Example #4
0
        private static double GetHorizontalOffset(Size popupSize, Size targetSize, HorizontalPlacement horizontalPlacement)
        {
            switch (horizontalPlacement)
            {
            case HorizontalPlacement.Left:
                return(0);

            case HorizontalPlacement.Right:
                return(targetSize.Width - popupSize.Width);

            case HorizontalPlacement.Center:
                return(-(popupSize.Width / 2) + targetSize.Width / 2);
            }
            throw new ArgumentOutOfRangeException("horizontalPlacement");
        }
        private static double GetHorizontalOffset(HorizontalPlacement horizontalPlacement, double popupWidth, double targetWidth, double offsetWidth)
        {
            var horizontalOffset = offsetWidth;

            switch (horizontalPlacement)
            {
            case HorizontalPlacement.Left:
                horizontalOffset += -popupWidth;
                break;

            case HorizontalPlacement.Center:
                horizontalOffset += targetWidth / 2 - popupWidth / 2;
                break;

            case HorizontalPlacement.Right:
                horizontalOffset += targetWidth;
                break;

            default:
                throw new Exception("Invalid Vertical Placement");
            }

            return(horizontalOffset);
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlacementOptions"/> class.
 /// </summary>
 /// <param name="horizontal">The <see cref="HorizontalPlacement"/>.</param>
 /// <param name="vertical">The <see cref="VerticalPlacement"/>.</param>
 /// <param name="offset">The offset.</param>
 public PlacementOptions(HorizontalPlacement horizontal, VerticalPlacement vertical, double offset)
 {
     this.Vertical   = vertical;
     this.Horizontal = horizontal;
     this.Offset     = offset;
 }
Example #7
0
        /// <summary>
        /// Usage: In XAML, add the following to your tooltip:
        ///     Placement="Custom" CustomPopupPlacementCallback="CustomPopupPlacementCallback"
        /// and call this method from the CustomPopupPlacementCallback.
        /// </summary>
        public static CustomPopupPlacement[] PlacePopup(Size popupSize, Size targetSize, Point offset, VerticalPlacement verticalPlacement, HorizontalPlacement horizontalPlacement)
        {
            Point p = new Point {
                X = GetHorizontalOffset(popupSize, targetSize, horizontalPlacement),
                Y = GetVerticalOffset(popupSize, targetSize, verticalPlacement)
            };

            return(new[] {
                new CustomPopupPlacement(p, PopupPrimaryAxis.Horizontal)
            });
        }
 public PlacementOptions(HorizontalPlacement horizontal, VerticalPlacement vertical, double offset)
 {
     this.Vertical = vertical;
     this.Horizontal = horizontal;
     this.Offset = offset;
 }
 private static bool TryParsePlacements(string arg1, string arg2, out HorizontalPlacement horizontal, out VerticalPlacement vertical)
 {
     vertical = default(VerticalPlacement);
     return (Enum.TryParse(arg1, true, out horizontal) &&
             Enum.TryParse(arg2, true, out vertical)) ||
            (Enum.TryParse(arg2, true, out horizontal) &&
             Enum.TryParse(arg1, true, out vertical));
 }