示例#1
0
        public void ShowMessage(string message, string bgColor, string txtColor, ToastLength toastLength = ToastLength.Short)
        {
            grid = new Grid();
            if (!string.IsNullOrEmpty(bgColor))
            {
                grid.Background = ColorToBrush(bgColor);
            }
            TextBlock popupText = new TextBlock();

            popupText.Text   = message;
            popupText.Margin = new Thickness(8);
            if (!string.IsNullOrEmpty(txtColor))
            {
                popupText.Foreground = ColorToBrush(txtColor);
            }
            grid.Children.Add(popupText);
            grid.CornerRadius      = new CornerRadius(20);
            popup.Child            = grid;
            popup.HorizontalOffset = (Window.Current.Bounds.Width) / 2;
            popup.VerticalOffset   = (Window.Current.Bounds.Height - grid.ActualHeight) - 50;
            popup.IsOpen           = true;

            DispatcherTimer timer = new DispatcherTimer();

            if (toastLength.Equals(ToastLength.Short))
            {
                timer.Interval = TimeSpan.FromSeconds(5);
            }
            else
            {
                timer.Interval = TimeSpan.FromSeconds(15);
            }

            timer.Tick += Timer_Tick;

            timer.Start();
        }