Example #1
0
        public void ShowTopNoti(Xamarin.Forms.Page p, View noti, int msTTL = 1500)
        {
            var render = Convert(noti, p);

            if (render != null)
            {
                var nanchor = p.GetRenderer() as Canvas;
                p.WidthRequest = nanchor.ActualWidth - 10;

                if (noti.HeightRequest <= 0)
                {
                    var size = noti.GetSizeRequest(nanchor.ActualWidth - 10, XFPopupConst.SCREEN_HEIGHT / 2);
                    if (size.Request.Height > XFPopupConst.SCREEN_HEIGHT / 2)
                    {
                        noti.HeightRequest = XFPopupConst.SCREEN_HEIGHT / 2;
                    }
                    else
                    {
                        noti.HeightRequest = size.Request.Height;
                    }
                }

                noti.Layout(new Rectangle(0, 0, noti.WidthRequest, noti.HeightRequest));

                var nativePopup = new System.Windows.Controls.Primitives.Popup();
                nativePopup.VerticalOffset   = 0;
                nativePopup.HorizontalOffset = 0;

                var boder = new Border();
                boder.BorderThickness = new System.Windows.Thickness(1);
                boder.Padding         = new System.Windows.Thickness(5);
                boder.BorderBrush     = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 50, 50, 50));
                boder.Background      = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255));

                boder.VerticalAlignment   = VerticalAlignment.Top;
                boder.HorizontalAlignment = HorizontalAlignment.Stretch;

                boder.Width        = noti.WidthRequest + 10;
                boder.Height       = noti.HeightRequest + 10;
                boder.CornerRadius = new CornerRadius(5);

                var elm = (render as Panel);
                elm.VerticalAlignment   = VerticalAlignment.Top;
                elm.HorizontalAlignment = HorizontalAlignment.Left;
                boder.Child             = elm;

                nativePopup.Child  = boder;
                nativePopup.IsOpen = true;

                //
                byte count           = 0;
                var  dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                dispatcherTimer.Tick += (object sender, EventArgs e) => {
                    count++;
                    if (count >= 10)
                    {
                        dispatcherTimer.Stop();
                        nativePopup.IsOpen = false;
                    }

                    boder.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb((byte)(255 - count * 25), 255, 255, 255));
                };

                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, msTTL / 10);
                dispatcherTimer.Start();
            }
        }