示例#1
0
        //public OpenWindowService(MainWindow mainWindow)
        //{
        //    _mainWidnow = mainWindow;
        //}
        public void CreatePopUpWindow(string mode, int delayMilliSeconds, string popUpSizeToContent)
        {
            Point       pt          = SystemParameters.WorkArea.TopLeft;
            PopUpWindow popUpWindow = new PopUpWindow()
            {
                DataContext = new PopUpWindowModel(new Models.PopUp(new OpenWindowService()), new OpenWindowService(), new ConfigProvider())
            };

            switch (mode)
            {
            case "default":
                popUpWindow.Loaded += (object sender, RoutedEventArgs e) =>
                {
                    pt.Offset(SystemParameters.WorkArea.Width, SystemParameters.WorkArea.Height);
                    pt.Offset(-popUpWindow.Width, -popUpWindow.Height);
                    popUpWindow.Left    = pt.X - 5;
                    popUpWindow.Top     = pt.Y - 5;
                    popUpWindow.Opacity = 1;
                };
                popUpWindow.ShowActivated = false;
                popUpWindow.Show();
                break;

            case "appear":
                DoubleAnimation fadeIn = new DoubleAnimation(1, TimeSpan.FromSeconds(0.2));
                popUpWindow.BeginAnimation(UIElement.OpacityProperty, fadeIn);

                Task.Run(() =>
                {
                    Thread.Sleep(delayMilliSeconds);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        DoubleAnimation fadeOut = new DoubleAnimation(0, TimeSpan.FromSeconds(0.8));
                        popUpWindow.BeginAnimation(UIElement.OpacityProperty, fadeOut);
                    });
                });
                popUpWindow.Loaded += (object sender, RoutedEventArgs e) =>
                {
                    pt.Offset(SystemParameters.WorkArea.Width, SystemParameters.WorkArea.Height);
                    pt.Offset(-popUpWindow.Width, -popUpWindow.Height);
                    popUpWindow.Left    = pt.X - 5;
                    popUpWindow.Top     = pt.Y - 5;
                    popUpWindow.Opacity = 0;
                };
                popUpWindow.ShowActivated = false;
                popUpWindow.Show();
                break;

            case "popup":
                popUpWindow.Loaded += (object sender, RoutedEventArgs e) =>
                {
                    pt.Offset(SystemParameters.WorkArea.Width, SystemParameters.WorkArea.Height);
                    pt.Offset(-popUpWindow.Width, 2 * popUpWindow.Height);
                    popUpWindow.Left    = pt.X;
                    popUpWindow.Top     = pt.Y;
                    popUpWindow.Opacity = 1;
                };
                popUpWindow.ShowActivated = false;
                popUpWindow.Show();
                break;
            }
        }