示例#1
0
        void AddBusyToPopup(Window targetWindow)
        {
            if (targetWindows.Contains(targetWindow))
            {
                return;
            }

            FrameworkElement targetElement =
                typeof(FrameworkElement).IsAssignableFrom(targetWindow.Content.GetType()) ? (FrameworkElement)targetWindow.Content : null;

            targetElements.Add(targetElement);

            if (targetElement != null)
            {
                BusyControl busyControl = new BusyControl();
                targetElement.SetValue(AdornerBehavior.ControlProperty, busyControl);
                targetElement.SetValue(AdornerBehavior.ShowAdornerProperty, true);

                busyControl.BeginAnimation();

                busyControls.Add(busyControl);
            }
            else
            {
                busyControls.Add(null);
            }

            targetWindows.Add(targetWindow);
        }
示例#2
0
        public void ShowBusy(string text, string[] windowNames)
        {
            counter++;
            if (counter > 1) // busy is already showing
            {
                return;
            }

            // Get all windows
            targetWindows = Application.Current.Windows.OfType <Window>().ToList();

            //targetWindows = new List<Window>{Application.Current.Windows.OfType<Window>().SingleOrDefault(w => w.IsActive)};
            // Get the element on which busy control will be shown
            foreach (var targetWindow in targetWindows)
            {
                //FrameworkElement targetElement =
                //    typeof(FrameworkElement).IsAssignableFrom(targetWindow.Content.GetType()) ? (FrameworkElement)targetWindow.Content : null;
                FrameworkElement targetElement = null;
                if (targetWindow.Content.GetType() == typeof(System.Windows.Controls.Grid))
                {
                    targetElement = (FrameworkElement)targetWindow.Content;
                }
                else if (targetWindow.Content.GetType() == typeof(System.Windows.Documents.AdornerDecorator)) // Hack for popup windows
                {
                    var decorator = targetWindow.Content as System.Windows.Documents.AdornerDecorator;
                    var grid      = decorator.Child as System.Windows.Controls.Grid;
                    if (grid != null)
                    {
                        targetElement = grid;
                    }
                }
                else
                {
                    targetElement = typeof(FrameworkElement).IsAssignableFrom(targetWindow.Content.GetType()) ? (FrameworkElement)targetWindow.Content : null;
                }
                targetElements.Add(targetElement);
                if (targetElement != null)
                {
                    BusyControl busyControl = new BusyControl();
                    if (!string.IsNullOrEmpty(text))
                    {
                        busyControl.tbLoadingText.Text = text;
                    }
                    targetElement.SetValue(AdornerBehavior.ControlProperty, busyControl);
                    targetElement.SetValue(AdornerBehavior.ShowAdornerProperty, true);
                    if (windowNames != null && !windowNames.Contains(targetWindow.Name))
                    {
                        busyControl.OverlayWithoutAnimation();
                    }
                    else
                    {
                        busyControl.BeginAnimation();
                    }

                    busyControls.Add(busyControl);
                }
                else
                {
                    busyControls.Add(null);
                }
            }
        }