Esempio n. 1
0
        /// <summary>
        /// 根据三角形方向设置消息框的水平位置,偏左还是偏右
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        public static void OnDirectionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AngleBorder angleBorder = d as AngleBorder;

            if (angleBorder != null)
            {
                switch ((EnumPlacement)e.NewValue)
                {
                case EnumPlacement.LeftTop:
                case EnumPlacement.LeftBottom:
                case EnumPlacement.LeftCenter:
                case EnumPlacement.RightTop:
                case EnumPlacement.RightBottom:
                case EnumPlacement.RightCenter:
                    angleBorder.TailWidth  = 6;
                    angleBorder.TailHeight = 12;
                    break;

                case EnumPlacement.TopLeft:
                case EnumPlacement.TopCenter:
                case EnumPlacement.TopRight:
                case EnumPlacement.BottomLeft:
                case EnumPlacement.BottomCenter:
                case EnumPlacement.BottomRight:
                    angleBorder.TailWidth  = 12;
                    angleBorder.TailHeight = 6;
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 2
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            this.AllowsTransparency = true;
            //this.StaysOpen = false;

            UIElement element = this.Child;

            this.Child = null;

            Grid root = new Grid()
            {
                Margin = new Thickness(10),
            };

            #region 阴影
            //Border shadow = new Border()
            //{
            //    Background = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
            //    SnapsToDevicePixels = true,
            //    UseLayoutRounding = true,
            //    CornerRadius = new CornerRadius(3),
            //};
            //DropShadowEffect shadowEffect = new DropShadowEffect()
            //{
            //    BlurRadius = 10,
            //    Opacity = 0.2,
            //    ShadowDepth = 0,
            //    Color = Color.FromRgb(109, 129, 154),
            //};
            //shadow.SetValue(Border.EffectProperty, shadowEffect);
            //root.Children.Add(shadow);
            #endregion

            #region 设置阴影的边距,防止出现白边
            //switch (this.PlacementEx)
            //{
            //    case EnumPlacement.LeftTop:
            //    case EnumPlacement.LeftBottom:
            //    case EnumPlacement.LeftCenter:
            //        shadow.Margin = new Thickness(0, 0, 8, 0);
            //        break;
            //    case EnumPlacement.RightTop:
            //    case EnumPlacement.RightBottom:
            //    case EnumPlacement.RightCenter:
            //        shadow.Margin = new Thickness(8, 0, 0, 0);
            //        break;
            //    case EnumPlacement.TopLeft:
            //    case EnumPlacement.TopCenter:
            //    case EnumPlacement.TopRight:
            //        shadow.Margin = new Thickness(0, 0, 0, 8);
            //        break;
            //    case EnumPlacement.BottomLeft:
            //    case EnumPlacement.BottomCenter:
            //    case EnumPlacement.BottomRight:
            //        shadow.Margin = new Thickness(0, 8, 0, 0);
            //        break;
            //    default:
            //        break;
            //}
            #endregion

            angleBorder = new AngleBorder()
            {
                Background      = this.Background,
                CornerRadius    = this.CornerRadius,
                BorderThickness = this.BorderThickness,
                BorderBrush     = this.BorderBrush,
            };
            switch (this.PlacementEx)
            {
            case EnumPlacement.LeftTop:
                angleBorder.Placement = EnumPlacement.RightTop;
                break;

            case EnumPlacement.LeftBottom:
                angleBorder.Placement = EnumPlacement.RightBottom;
                break;

            case EnumPlacement.LeftCenter:
                angleBorder.Placement = EnumPlacement.RightCenter;
                break;

            case EnumPlacement.RightTop:
                angleBorder.Placement = EnumPlacement.LeftTop;
                break;

            case EnumPlacement.RightBottom:
                angleBorder.Placement = EnumPlacement.LeftBottom;
                break;

            case EnumPlacement.RightCenter:
                angleBorder.Placement = EnumPlacement.LeftCenter;
                break;

            case EnumPlacement.TopLeft:
                angleBorder.Placement = EnumPlacement.BottomLeft;
                break;

            case EnumPlacement.TopCenter:
                angleBorder.Placement = EnumPlacement.BottomCenter;
                break;

            case EnumPlacement.TopRight:
                angleBorder.Placement = EnumPlacement.BottomRight;
                break;

            case EnumPlacement.BottomLeft:
                angleBorder.Placement = EnumPlacement.TopLeft;
                break;

            case EnumPlacement.BottomCenter:
                angleBorder.Placement = EnumPlacement.TopCenter;
                break;

            case EnumPlacement.BottomRight:
                angleBorder.Placement = EnumPlacement.TopRight;
                break;

            default:
                break;
            }

            //在原有控件基础上,最外层套一个AngleBorder
            angleBorder.Child = element;

            root.Children.Add(angleBorder);

            this.Child = root;
        }