Ejemplo n.º 1
0
 /// <summary> 显示自定义气泡消息 </summary>
 public static void ShowNotifyDialogMessage(string message, string title = null, int closeTime = -1)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         NotifyDialogWindow.ShowMessage(message, title, closeTime);
     });
 }
        /// <summary>
        /// 弹出消息框
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="owner">父级窗体</param>
        public static void ShowDialog(string message, Grid owner)
        {
            //蒙板
            Grid layer = new Grid()
            {
                Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0))
            };

            //在上面放一层蒙板
            owner.Children.Add(layer);

            //弹出消息框
            NotifyDialogWindow box = new NotifyDialogWindow();

            box.Tag     = owner;
            box.Title   = message;
            box.Closed += Window_Closed;

            FButton f = new FButton();

            f.Content = "确定";
            f.Margin  = new Thickness(0, 0, 20, 0);
            //f.Style = f.FindResource("S.FButton.Default") as Style;

            //f.Style = myResourceDictionary["FButton_LinkButton"] as Style;

            f.Click += (object sender, RoutedEventArgs e) =>
            {
                box.CloseAnimation(box);
            };

            box.actionPanel.Children.Add(f);

            box.ShowDialog();
        }
        /// <summary> 显示窗口 </summary>
        public static int ShowDialogWith(string messge, string title = null, params Tuple <string, Action <NotifyDialogWindow> >[] acts)
        {
            int result = -1;

            NotifyDialogWindow m = new NotifyDialogWindow();

            // Todo :消息 2017-07-28 10:46:24
            m.messageText.Text = messge;

            var array = messge.ToArray();

            var c = array.ToList().Count(l => l == '\r');

            m.Height += c * 30;

            List <Label> ls = new List <Label>();

            if (!string.IsNullOrEmpty(title))
            {
                m.Title = title;
            }

            if (acts == null || acts.Length == 0)
            {
            }
            else
            {
                m.actionPanel.Children.Clear();

                // Todo :根据事件加载按钮 2017-07-28 10:46:07
                foreach (var item in acts)
                {
                    FButton f = new FButton();
                    f.Content = item.Item1;
                    f.Margin  = new Thickness(0, 0, 10, 0);
                    //f.FIcon = "";
                    //f.SetPressed(false);

                    f.Click += (object sender, RoutedEventArgs e) =>
                    {
                        if (item.Item2 != null)
                        {
                            item.Item2(m);
                        }

                        result = acts.ToList().IndexOf(item);

                        m.CloseAnimation(m);
                    };

                    m.actionPanel.Children.Add(f);
                }
            }

            m.ShowDialog();


            return(result);
        }
        /// <summary> 显示窗口 </summary>
        public static void ShowMessage(string messge, string title = null, int closeTime = -1)
        {
            NotifyDialogWindow m = new NotifyDialogWindow();

            m.messageText.Text = messge;

            m.actionPanel.Visibility = Visibility.Collapsed;

            var array = messge.ToArray();

            var c = array.ToList().Count(l => l == '\r');

            m.Height += c * 30;

            if (!string.IsNullOrEmpty(title))
            {
                m.Title = title;
            }

            if (closeTime != -1)
            {
                Action action = () =>
                {
                    for (int i = closeTime; i > 0; i--)
                    {
                        Thread.Sleep(1000);

                        m.Dispatcher.Invoke(() => m.Title = title + " 关闭倒计时(" + i + ")秒");
                    }

                    m.Dispatcher.Invoke(() => m.CloseAnimation(m));
                };

                Task task = new Task(action);
                task.Start();
            }

            m.Show();
        }
        /// <summary> 显示窗口 </summary>
        public static bool ShowDialog(string messge, string title = null, int closeTime = -1, params Tuple <string, Action>[] acts)
        {
            NotifyDialogWindow m = new NotifyDialogWindow();

            m.messageText.Text = messge;
            var array = messge.ToArray();

            var c = array.ToList().Count(l => l == '\r');

            m.Height += c * 30;

            if (!string.IsNullOrEmpty(title))
            {
                m.Title = title;
            }

            if (acts == null || acts.Length == 0)
            {
            }
            else
            {
                m.actionPanel.Children.Clear();

                foreach (var item in acts)
                {
                    FButton f = new FButton();
                    f.Content = item.Item1;
                    f.Margin  = new Thickness(0, 0, 0, 0);
                    //f.Style = f.FindResource("S.FButton.Default") as Style;

                    f.Click += (object sender, RoutedEventArgs e) =>
                    {
                        m.CloseAnimation(m);

                        if (item.Item2 != null)
                        {
                            item.Item2.Invoke();
                        }
                    };

                    m.actionPanel.Children.Add(f);
                }
            }

            if (closeTime != -1)
            {
                Action action = () =>
                {
                    for (int i = closeTime; i > 0; i--)
                    {
                        Thread.Sleep(1000);

                        m.Dispatcher.Invoke(() => m.Title = title + " 关闭倒计时(" + i + ")秒");
                    }

                    m.Dispatcher.Invoke(() => m.CloseAnimation(m));
                };


                Task task = new Task(action);
                task.Start();
            }


            m.ShowDialog();



            return(m.Result);
        }