其他分享
首页 > 其他分享> > 以圆角裁剪控件

以圆角裁剪控件

作者:互联网

        public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (sender is FrameworkElement element)
            {
                if (e.NewValue is Thickness cornervalue)
                {
                    element.SizeChanged -= SizeChanged;
                    element.SizeChanged += SizeChanged;
                }
            }
        }

        /// <summary>
        /// 尺寸改变时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var img = (FrameworkElement)sender;
            if (img.Clip != null)
                img.Clip = null;
            var raidus = UIElementClipCorner.GetValue(img);
            var radiusCornerclip = new RectangleGeometry()
            {
                RadiusX = raidus.Left,
                RadiusY = raidus.Top,
                Rect = new Rect
                {
                    Height = img.RenderSize.Height,
                    Width = img.RenderSize.Width
                }
            };
            img.Clip = radiusCornerclip;
        }

 

标签:控件,圆角,sender,img,raidus,裁剪,SizeChanged,Clip,var
来源: https://www.cnblogs.com/MichaelJson/p/16309566.html