void Initialize()
        {
            var container = new Grid
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                RowSpacing        = 0,
                Margin            = new Thickness(6)
            };

            _background = new Rectangle
            {
                Fill            = Brush.Transparent,
                HeightRequest   = 18,
                WidthRequest    = 18,
                RadiusX         = 2,
                RadiusY         = 2,
                Stroke          = Color,
                StrokeThickness = 2
            };

            _glyph = new Path
            {
                Aspect            = Stretch.Uniform,
                Stroke            = Brush.White,
                StrokeThickness   = 1,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                HeightRequest     = 14,
                WidthRequest      = 14,
                Opacity           = 0,
                Margin            = new Thickness(2)
            };

            var pathGeometryConverter = new PathGeometryConverter();

            if (_glyph is Path path && pathGeometryConverter.ConvertFromInvariantString("M30.561941,0L31.997,1.393004 10.467954,23.597999 0,15.350999 1.2379759,13.780992 10.287961,20.909952z") is Geometry data)
            {
                path.Data = data;
            }

            container.Children.Add(_background);
            container.Children.Add(_glyph);

            Content = container;

            _tapGestureRecognizer = new TapGestureRecognizer();

            UpdateIsEnabled();
        }
 public Geometry ProvideValue(IServiceProvider serviceProvider)
 {
     return(PathGeometryConverter.ConvertFromInvariantString(Path) as Geometry);
 }
Beispiel #3
0
        void start()
        {
            for (int i = 0; i < 10; i++)
            {
                var p = new Xamarin.Forms.Shapes.Path();
                p.Aspect = Stretch.None;

                mPathList.Add(p);
                this.Children.Add(p);
                p.Data = (Geometry)mGeometryConverter.ConvertFromInvariantString("M 0,20 L 0.8,19 L 10,19 L 10,21 L 0.8,21 Z"); // XamarinForms 版本貌似不能显示负数的内容, 故起始由9点方位的横线开始

                p.Stroke  = new SolidColorBrush(Color.White);
                p.Fill    = new SolidColorBrush(Color.White);
                p.Opacity = mMinOpacity;

                var tg = new TransformGroup();
                // TransformGroup 需要进行 2个步骤
                // 1 向上位移 50 ==> Y = -50;
                // 2 旋转一定角度, 让 12 个 Path 组成一个圆 ==> Angle = i * 30;

                var tt = new TranslateTransform();
                // tt.Y = -13; // WPF
                tt.X = 2; // 可以调整的范围 0 ~ 5
                tg.Children.Add(tt);

                var rt = new RotateTransform();
                rt.Angle   = i * 36; // 360 / 10 = 36
                rt.CenterX = 20;     // XamarinForms 版本貌似不能显示负数的内容, 故起始由9点方位的横线开始, 所以旋转以 20, 20 为中心
                rt.CenterY = 20;     // XamarinForms 版本貌似不能显示负数的内容, 故起始由9点方位的横线开始, 所以旋转以 20, 20 为中心
                tg.Children.Add(rt);

                var st = new ScaleTransform();
                mSTList.Add(st); // 程序员可以调整缩放
                st.ScaleX = 1;
                st.ScaleY = 1;
                tg.Children.Add(st);

                p.RenderTransform = tg;

                //var ani = new DoubleAnimation();
                //ani.From = mMaxOpacity;
                //ani.To = mMinOpacity;
                //ani.Duration = new Duration(TimeSpan.FromSeconds(1));

                //// 为了实现依次闪烁, 错开每个动画的开始时间
                //ani.BeginTime = TimeSpan.FromMilliseconds(i * 1000 / 12);
                //ani.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;

                //p.BeginAnimation(System.Windows.Shapes.Path.OpacityProperty, ani);

                Animation mStoryboard = new Animation();

                // double total = 6000d;
                double total = 1000d;

                double k1 = i * 100d / total;

                // 等待动画开始执行
                if (i > 0)
                {
                    Animation s1 = new Animation
                                   (
                        callback: v => p.Opacity = v,
                        start: mMinOpacity,
                        end: mMinOpacity,
                        easing: Easing.Linear,
                        finished: null
                                   );

                    mStoryboard.Add
                    (
                        beginAt: 0,
                        finishAt: k1,
                        animation: s1
                    );
                }

                // 动画开始执行
                Animation s2 = new Animation
                               (
                    callback: v => p.Opacity = v,
                    start: mMaxOpacity,
                    end: mMinOpacity,
                    easing: Easing.Linear,
                    finished: null
                               );

                mStoryboard.Add
                (
                    beginAt: k1,
                    finishAt: 1,
                    animation: s2
                );

                mStoryboard.Commit
                (
                    owner: p,
                    name: AnimationName,
                    rate: 16,
                    length: uint.Parse(total.ToString()),
                    easing: Easing.Linear,
                    finished: null,
                    repeat: () => { return(true); }
                );

                mAnimationList.Add(mStoryboard);
            }
        }