Exemple #1
0
        Window FindOwner()
        {
            Window result = WindowObject as Window;

            if (result != null)
            {
                return(result);
            }

            bool visualTreeSearch = SplashScreenOwner.GetPreferVisualTreeForOwnerSearch(WindowObject);

            if (visualTreeSearch)
            {
                result = LayoutHelper.FindParentObject <Window>(WindowObject);
            }
            if (result == null)
            {
                result = Window.GetWindow(WindowObject);
            }

            if (!visualTreeSearch && result != null && SplashScreenOwner.GetPreferVisualTreeForOwnerSearch(result))
            {
                visualTreeSearch = true;
                var newWindow = LayoutHelper.FindParentObject <Window>(WindowObject);
                if (newWindow != null)
                {
                    result = newWindow;
                }
            }
            return(result);
        }
            public void Release(bool activateWindowIfNeeded)
            {
                if (owner == null)
                {
                    return;
                }

                var    window = owner.Window;
                IntPtr handle = owner.WindowHandle;

                owner.Initialized -= OnOwnerInitialized;
                owner              = null;
                if (window == null)
                {
                    return;
                }

                InvokeOnThread(window.Dispatcher, () => {
                    if (activateWindowIfNeeded && !window.IsActive)
                    {
                        window.Activate();
                    }

                    UnlockWindow(handle);
                }, DispatcherPriority.Render, false);
            }
 void CreateLocker(SplashScreenOwner parentContainer, bool lockWindow)
 {
     if (lockWindow)
     {
         locker = new WindowLocker(parentContainer);
     }
 }
        static Window CreateSplashScreenWindow(object parameter)
        {
            object[]             parameters    = (object[])parameter;
            bool                 useFadeEffect = (bool)parameters[0];
            SplashScreenOwner    owner         = (SplashScreenOwner)parameters[1];
            SplashScreenLocation childLocation = (SplashScreenLocation)parameters[2];
            bool                 lockWindow    = (bool)parameters[3];

            return(new LoadingDecoratorWindow(useFadeEffect, owner, childLocation, lockWindow));
        }
 public WindowLocker(SplashScreenOwner owner)
 {
     this.owner = owner;
     if (!owner.IsInitialized)
     {
         owner.Initialized += OnOwnerInitialized;
     }
     else
     {
         OnInitialized();
     }
 }
            public void Release()
            {
                if (isDisposed)
                {
                    return;
                }

                UnsubscribeChildEvents();
                UnsubscribeParentEvents();
                childWindow         = null;
                childHandle         = IntPtr.Zero;
                parent.Initialized -= OnParentInitialized;
                parent              = null;
                isDisposed          = true;
            }
            public WindowArranger(SplashScreenOwner parent, SplashScreenLocation childLocation)
            {
                if (parent == null)
                {
                    throw new ArgumentNullException("parent");
                }

                this.childLocation = childLocation;
                this.parent        = parent;
                if (parent.IsInitialized)
                {
                    ParentInitializationComplete();
                }
                else
                {
                    parent.Initialized += OnParentInitialized;
                }
            }
 public LoadingDecoratorWindow(bool useFadeEffect, SplashScreenOwner parentContainer, SplashScreenLocation childLocation, bool lockParent)
 {
     WindowStyle           = WindowStyle.None;
     AllowsTransparency    = true;
     ShowInTaskbar         = false;
     Background            = new SolidColorBrush(Colors.Transparent);
     SizeToContent         = SizeToContent.WidthAndHeight;
     WindowStartupLocation = WindowStartupLocation.Manual;
     Left             = parentContainer.ControlStartupPosition.Left;
     Top              = parentContainer.ControlStartupPosition.Top;
     Width            = parentContainer.ControlStartupPosition.Width;
     Height           = parentContainer.ControlStartupPosition.Height;
     Topmost          = false;
     ShowActivated    = false;
     IsHitTestVisible = false;
     Focusable        = false;
     CreateArranger(parentContainer, childLocation);
     CreateLocker(parentContainer, lockParent);
     WindowFadeAnimationBehavior.SetEnableAnimation(this, useFadeEffect);
     Loaded += OnWindowLoaded;
 }
Exemple #9
0
 public static void Show(Type splashScreenType, WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen, SplashScreenOwner owner = null, SplashScreenClosingMode closingMode = SplashScreenClosingMode.Default)
 {
     CheckSplashScreenType(splashScreenType);
     if (typeof(Window).IsAssignableFrom(splashScreenType))
     {
         Func <object, Window> windowCreator = (p) => {
             Window splashWindow = (Window)Activator.CreateInstance(SplashScreenHelper.FindParameter <Type>(p));
             splashWindow.WindowStartupLocation = SplashScreenHelper.FindParameter(p, WindowStartupLocation.CenterScreen);
             return(splashWindow);
         };
         Show(windowCreator, null, new object[] { splashScreenType, startupLocation, owner, closingMode }, null);
     }
     else if (typeof(FrameworkElement).IsAssignableFrom(splashScreenType))
     {
         Func <object, Window> windowCreator = (p) => {
             Window res = DefaultSplashScreenWindowCreator(p);
             WindowFadeAnimationBehavior.SetEnableAnimation(res, true);
             return(res);
         };
         Show(windowCreator, CreateDefaultSplashScreen, new object[] { startupLocation, owner, closingMode }, new object[] { splashScreenType });
     }
 }
Exemple #10
0
 public static void Show <T>(WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen, SplashScreenOwner owner = null, SplashScreenClosingMode closingMode = SplashScreenClosingMode.Default)
 {
     Show(typeof(T), startupLocation, owner, closingMode);
 }
Exemple #11
0
 public static void Show <T>(Action action, WindowStartupLocation startupLocation = WindowStartupLocation.CenterScreen, SplashScreenOwner owner = null, SplashScreenClosingMode closingMode = SplashScreenClosingMode.Default)
 {
     Show <T>(startupLocation, owner, closingMode);
     try {
         action();
     } finally {
         Close();
     }
 }
 void CreateArranger(SplashScreenOwner parentContainer, SplashScreenLocation childLocation)
 {
     arranger = new WindowArranger(parentContainer, childLocation);
     arranger.ParentClosed += OnParentWindowClosed;
     arranger.AttachChild(this);
 }