码迷,mamicode.com
首页 > 其他好文 > 详细

剪切具有CornerRadius的RectangleGeometry(可能在Ripple中用到)

时间:2017-09-08 11:44:48      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:return   try   tty   element   stat   ack   multi   enc   not   

剪切具有CornerRadius的RectangleGeometry(可能在Ripple中用到)

1、新建Converter

public class BorderClipConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length == 3 && values[0] is double && values[1] is double && values[2] is CornerRadius)
        {
            var width = (double)values[0];
            var height = (double)values[1];

            if (width < Double.Epsilon || height < Double.Epsilon)
            {
                return Geometry.Empty;
            }

            var radius = (CornerRadius)values[2];

            var clip = new RectangleGeometry(new Rect(1.5, 1.5, width - 3, height - 3), radius.TopLeft, radius.TopLeft);
            clip.Freeze();

            return clip;
        }

        return DependencyProperty.UnsetValue;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
} 

2、添加Converter

<controls:Ripple.Clip>
                                <MultiBinding Converter="{StaticResource BorderClipConverter}">
                                    <Binding Path="ActualWidth" ElementName="border" />
                                    <Binding Path="ActualHeight" ElementName="border" />
                                    <Binding Path="CornerRadius" ElementName="border" />
                                </MultiBinding>
                            </controls:Ripple.Clip>

 

 

剪切具有CornerRadius的RectangleGeometry(可能在Ripple中用到)

标签:return   try   tty   element   stat   ack   multi   enc   not   

原文地址:http://www.cnblogs.com/akiing/p/7493358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!