示例#1
0
        public void ShowToast(string s)
        {
            if (_toast.IsVisible && _toast.Text == s)
            {
                return;
            }

            _toast.IsVisible = true;
            _toast.Text      = s;
            if (_toast.AnimationIsRunning(ToastAnimationName))
            {
                _toast.AbortAnimation(ToastAnimationName);
            }

            _toast.Animate(ToastAnimationName, d => _toast.Opacity = d, 1, 0, length: 2000u, finished: (v, r) => _toast.IsVisible = false);
            ForceLayout();
        }
示例#2
0
        void beginAnimation_ActualMethod()
        {
            if (this.Width >= label.Width)
            {
                //string msg = $"无需使用滚动方式显示";
                //System.Diagnostics.Debug.WriteLine(msg);
                return;
            }

            if (mStoryboard != null)
            {
                try
                {
                    label.AbortAnimation(mAnimationName);
                }
                finally
                {
                    mStoryboard = null;
                }
            }

            NewsTicker();
        }
示例#3
0
        protected async Task RunMessagePattern(int fadeTimeMillis, int duration, CancellationToken cancellationToken)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            // Cancel previous running.
            AnimateOnMain(() =>
            {
                if (messageBox.AnimationIsRunning("FadeTo"))
                {
                    messageBox.AbortAnimation("FadeTo");
                }
            });

            bool   initial          = true;
            string message          = string.Empty;
            int    durationRequired = 0;

            while (!cancellationToken.IsCancellationRequested) // Keep running pattern until done aerating.
            {
                cancellationToken.ThrowIfCancellationRequested();

                for (int i = 0; i < messagePattern.Count; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (messagePattern[i] == MessageType.FUN)
                    {
                        message = funMessageSource.GetNext();
                    }
                    else if (messagePattern[i] == MessageType.FACT)
                    {
                        message = factMessageSource.GetNext();
                    }

                    if (initial)
                    {
                        durationRequired = EstimatedReadTimeMillis(message) + fadeTimeMillis;
                    }
                    else
                    {
                        durationRequired = EstimatedReadTimeMillis(message) + (fadeTimeMillis * 2);
                    }

                    // Don't show if too close to end, user wont' be able to read text.
                    if (durationRequired <= Math.Abs(duration - sw.ElapsedMilliseconds) + 500)
                    {
                        AnimateOnMain(async() =>
                        {
                            if (!initial) // Don't fade out on first.
                            {
                                if (!messageBox.AnimationIsRunning("FadeTo"))
                                {
                                    await messageBox.FadeTo(0, (uint)fadeTimeMillis);
                                }
                            }
                            initial         = false; // Always fade from now on.
                            messageBox.Text = message;
                            if (!messageBox.AnimationIsRunning("FadeTo"))
                            {
                                await messageBox.FadeTo(1.0d, (uint)fadeTimeMillis);
                            }
                        });
                        await Task.Delay(durationRequired, cancellationToken);
                    }
                    else
                    {
                        await Task.Delay((int)Math.Abs(duration - sw.ElapsedMilliseconds));
                    }
                }
            }
        }