Exemplo n.º 1
0
 public static void ShowwithAnimation(this Window window)
 {
     window.Visibility = Visibility.Visible;
     window.Topmost = false;
     TimeSpan slidetime = TimeSpan.FromSeconds(0.3);
     DoubleAnimation bottomAnimation = new DoubleAnimation();
     bottomAnimation.Duration = new Duration(slidetime);
     double top = window.Top;
     bottomAnimation.From = window.Top + 25;
     bottomAnimation.To = window.Top;
     bottomAnimation.FillBehavior = FillBehavior.Stop;
     bottomAnimation.Completed += (s, e) =>
     {
         window.Topmost = true;
         // Set the final position again. This covers a case where frames are dropped.
         // and the window ends up over the taskbar instead.
         window.Top = top;
         window.Activate();
         window.Focus();
     };
     var easing = new QuinticEase();
     easing.EasingMode = EasingMode.EaseOut;
     bottomAnimation.EasingFunction = easing;
     window.BeginAnimation(Window.TopProperty, bottomAnimation);
 }
Exemplo n.º 2
0
 public static void ToggleTopmost(this Window window)
 {
    // Verify.IsNotNull(window, "window");
    window.Topmost = !window.Topmost;
    if(window.Topmost)
       window.Activate();
 }
Exemplo n.º 3
0
 public static void ShowThisDarnWindowDammitWpfEdition(this Window window)
 {
     window.Show();
     if (window.WindowState == WindowState.Minimized) window.WindowState = WindowState.Normal;
     window.BringIntoView();
     window.Activate();
 }
Exemplo n.º 4
0
 public static void ToggleVisibility(this Window window)
 {
    // Verify.IsNotNull(window, "window");
    if (window.Visibility != Visibility.Visible)
    {
       window.Show();
       window.Activate();
    }
    else if (!window.IsActive)
    {
       window.Activate();
    }
    else
    {
       window.Hide();
    }
 }
Exemplo n.º 5
0
 public static void ShowNonBlockingModal(this Window window)
 {
     var parent = window.Owner;
     EventHandler parentDeactivate = (_, __) => { window.Activate(); };
     parent.Activated += parentDeactivate;
     EventHandler window_Closed = (_, __) => { parent.Activated -= parentDeactivate; };
     window.Show();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a view to a region and activates it.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="view">The view for the region.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="region"/> is <see langword="null" />.
        /// </exception>
        public static void AddAndActivate(this IRegion region, object view)
        {
            {
                Lokad.Enforce.Argument(() => region);
            }

            region.Add(view);
            region.Activate(view);
        }
 public static void Activate(this PP.Application app, bool WaitIfBusy = false, int RetryAttempt = 0)
 {
     try
     {
         app.Activate();
     }
     catch (COMException ex)
     {
         if (ex.ErrorCode == -2146823687) // Cannot activate application
             if (WaitIfBusy && RetryAttempt < 10)
             {
                 Thread.Sleep(2000);
                 app.Activate(WaitIfBusy, ++RetryAttempt);
             }
             else
                 throw ex;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Brings the window to the front of the z-order,
        ///     even if the window is a child of another application.
        /// </summary>
        public static Window SetOnTop(this Window window)
        {
            ThrowHelper.IfNullThenThrow(() => window);

            var oldValue = window.Topmost;
            window.Topmost = true;
            window.Activate();
            window.Topmost = oldValue;
            return window;
        }
 public static void Activate(this XL.Application app, bool WaitIfBusy = false, int RetryAttempt = 0)
 {
     throw new NotImplementedException("There's a stack overflow error in this routine!");
     try
     {
         app.Activate();
     }
     catch (COMException ex)
     {
         if (ex.ErrorCode == -2146823687) // Cannot activate application
             if (WaitIfBusy && RetryAttempt < 10)
             {
                 Thread.Sleep(2000);
                 app.Activate(WaitIfBusy, ++RetryAttempt);
             }
             else
                 throw ex;
     }
 }
Exemplo n.º 10
0
        public static void AddAndActivate(this IRegion region, object view, string viewName="")
        {
            if(viewName != "")
                region.Add(view, viewName);
            else
            {
                region.Add(view);
            }

            region.Activate(view);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Show form if not visible, otherwise just Activate.
 /// </summary>
 /// <param name="form">
 /// The form to show or activate.
 /// </param>
 public static void ShowOrActivate(this Form form)
 {
     if (form.Visible)
     {
         form.Activate();
     }
     else
     {
         form.Show();
     }
 }
Exemplo n.º 12
0
        public static void ShowwithAnimation(this Window window)
        {
            window.Visibility = Visibility.Visible;
            window.Topmost = false;
            window.Activate();

            var showAnimation = new DoubleAnimation
            {
                Duration = new Duration(TimeSpan.FromSeconds(0.3)),
                FillBehavior = FillBehavior.Stop,
                EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut }
            };
            var showAnimationOpacity = new DoubleAnimation
            {
                Duration = new Duration(TimeSpan.FromSeconds(0.1)),
                FillBehavior = FillBehavior.Stop,
                EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut }
            };

            var taskbarPosition = TaskbarService.TaskbarPosition;
            switch (taskbarPosition)
            {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    showAnimation.To = window.Left;
                    break;
                default:
                    showAnimation.To = window.Top;
                    break;
            }
            showAnimation.From = (taskbarPosition == TaskbarPosition.Top || taskbarPosition == TaskbarPosition.Left) ? showAnimation.To - 25 : showAnimation.To + 25;
            showAnimation.Completed += (s, e) =>
            {
                window.Topmost = true;
                window.Focus();
            };

            showAnimationOpacity.From = 0;
            showAnimationOpacity.To = 1;

            switch (taskbarPosition)
            {
                case TaskbarPosition.Left:
                case TaskbarPosition.Right:
                    window.ApplyAnimationClock(Window.LeftProperty, showAnimation.CreateClock());
                    break;
                default:
                    window.ApplyAnimationClock(Window.TopProperty, showAnimation.CreateClock());
                    break;
            }

            window.ApplyAnimationClock(Window.OpacityProperty, showAnimationOpacity.CreateClock());
            _windowVisible = true;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Activates the view associated with the given parameter.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="parameter">The parameter.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="region"/> is <see langword="null" />.
        /// </exception>
        public static void ActivateByParameter(this IRegion region, Parameter parameter)
        {
            {
                Lokad.Enforce.Argument(() => region);
            }

            var view = region.GetViewByParameter(parameter);
            if (view != null)
            {
                region.Activate(view);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Shows and activates form.
        /// </summary>
        /// <param name="form"></param>
        public static void ShowActivate(this Form form)
        {
            if (!form.Visible) {
                form.Show();
            }

            if (form.WindowState == FormWindowState.Minimized) {
                form.WindowState = FormWindowState.Normal;
            }

            form.BringToFront();
            form.Activate();
        }
 /// <summary>
 /// Tries to activate the extension.
 /// </summary>
 /// <param name="extension">The extension.</param>
 /// <returns></returns>
 public static bool TryActivate(this IExtension extension)
 {
     Trace.WriteLine("Activating: " + extension.AssemblyQualifiedName);
     try
     {
         extension.Activate();
         return true;
     }
     catch (Exception ex)
     {
         Trace.WriteLine(String.Format("Error: {0} {1} {2}", extension.AssemblyQualifiedName, ex.Message, ex.StackTrace));
         return false;
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Helper method to activate the form. Usually <see cref="Form.Activate"/> does all we need, but on some systems the MP2-Client's window
 /// is not being activated. In this case we need to call native methods to force it.
 /// </summary>
 public static void SafeActivate(this Form form)
 {
   if (form == Form.ActiveForm)
     return;
   form.Activate();
   if (form != Form.ActiveForm)
   {
     // Make Mediaportal window focused
     if (NativeMethods.SetForegroundWindow(form.Handle, true))
     {
       // no logging available here
     }
   }
 }
Exemplo n.º 17
0
        /// <summary>
        ///     Brings the form to the front of the z-order,
        ///     even if the form is a child of another application.
        /// </summary>
        public static Form SetOnTop(this Form form)
        {
            ThrowHelper.IfNullThenThrow(() => form);

            if (form.InvokeRequired)
            {
                form.Invoke(new MethodInvoker(delegate
                {
                    if (form.WindowState == FormWindowState.Minimized)
                        form.WindowState = FormWindowState.Normal;
                    form.Activate();
                }));
            }
            return form;
        }
Exemplo n.º 18
0
      public static void ToggleVisibility(this Window window, bool? visible = null)
      {
         bool forceHide = visible.HasValue && !visible.Value;
         // Verify.IsNotNull(window, "window");
         if (window.Visibility != Visibility.Visible && !forceHide)
         {
            window.Show();
         }
         else
         {
            window.Hide();
         }

         if (!window.IsActive && !forceHide)
         {
            window.Activate();
            window.Focus();
         }

      }
Exemplo n.º 19
0
        public static ThumbnailToolbarButton CreateThumbnailToolbarButton(this Gtk.Action action,
            Func<Gtk.Action, System.Drawing.Icon> icon_callback)
        {
            var button = new ThumbnailToolbarButton (id++) {
                DismissOnClick = false,
                Tooltip = action.Label.Replace ("_", ""),
                Enabled = action.Sensitive,
                Hidden = !action.Visible,
                Icon = icon_callback != null ? icon_callback (action) : null
            };

            button.Clicked += (o, e) => action.Activate ();

            action.AddNotification ("icon-name", (o, args) => button.Icon = icon_callback != null ? icon_callback (action) : null);
            action.AddNotification ("stock-id", (o, args) => button.Icon = icon_callback != null ? icon_callback (action) : null);
            action.AddNotification ("tooltip", (o, args) => button.Tooltip = action.Label.Replace ("_", ""));
            action.AddNotification ("sensitive", (o, args) => button.Enabled = action.Sensitive);
            action.AddNotification ("visible", (o, args) => button.Hidden = !action.Visible);

            return button;
        }
Exemplo n.º 20
0
		/// <summary>
		/// Activate a window from anywhere by attaching to the foreground window
		/// </summary>
		public static void GlobalActivate(this Window w)
		{
			//Get the process ID for this window's thread
			var interopHelper = new WindowInteropHelper(w);
			var thisWindowThreadId = GetWindowThreadProcessId(interopHelper.Handle, IntPtr.Zero);

			//Get the process ID for the foreground window's thread
			var currentForegroundWindow = GetForegroundWindow();
			var currentForegroundWindowThreadId = GetWindowThreadProcessId(currentForegroundWindow, IntPtr.Zero);

			//Attach this window's thread to the current window's thread
			AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, true);

			//Set the window position
			SetWindowPos(interopHelper.Handle, new IntPtr(0), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);

			//Detach this window's thread from the current window's thread
			AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, false);

			//Show and activate the window
			if (w.WindowState == WindowState.Minimized) w.WindowState = WindowState.Normal;
			w.Show();
			w.Activate();
		}
 public static void ShowAroundVisualOwner(this Form form, Form visualOwner)
 {
     if (!form.IsHandleCreated)
         form.CenterAroundVisualOwner(visualOwner);
     form.Show();
     form.Activate();
 }
Exemplo n.º 22
0
        /// <summary>
        /// Adds the given view and associates it with the given parameter.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="view">The view for the parameter.</param>
        /// <param name="parameter">The parameter.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="region"/> is <see langword="null" />.
        /// </exception>
        public static void AddAndActivateWithParameter(this IRegion region, object view, Parameter parameter)
        {
            {
                Lokad.Enforce.Argument(() => region);
            }

            region.AddWithParameter(view, parameter);
            region.Activate(view);
        }
Exemplo n.º 23
0
 public static bool ActivateCenteredToMouse(this Window window)
 {
     ComputeTopLeft(ref window);
     return window.Activate();
 }
Exemplo n.º 24
0
        /// <summary>
        /// Adds a view with a specified name to a region and activates it.
        /// </summary>
        /// <param name="region">The region.</param>
        /// <param name="view">The view for the region.</param>
        /// <param name="createChildRegion">If set to <see langword="true" /> a child region manager will be created.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="region"/> is <see langword="null" />.
        /// </exception>
        public static void AddAndActivate(this IRegion region, object view, bool createChildRegion)
        {
            {
                Lokad.Enforce.Argument(() => region);
            }

            region.Add(view, Guid.NewGuid().ToString(), createChildRegion);
            region.Activate(view);
        }
Exemplo n.º 25
0
        public static void FubuValidationWith(this Registry registry, IncludePackageAssemblies packageAssemblies, params Assembly[] assemblies)
        {
            registry.ForSingletonOf<ITypeDescriptorCache>().Use<TypeDescriptorCache>();
            registry.For<IValidator>().Use<Validator>();
            registry.For<IValidationSource>().Add<UniqueValidationSource>();
            registry.ForSingletonOf<IFieldRulesRegistry>().Add<FieldRulesRegistry>();
            registry.For<IValidationSource>().Add<FieldRuleSource>();

            var convention = new ValidationConvention();
            registry.Scan(x =>
            {
                assemblies.Each(x.Assembly);
                if (packageAssemblies == IncludePackageAssemblies.Yes)
                {
                    PackageRegistry.PackageAssemblies.Each(x.Assembly);
                }

                x.With(convention);
            });

            registry.Activate<IFieldRulesRegistry>("Applying explicit field validtion rules", fieldRules =>
            {
                convention.Registrations.Each(x => x.RegisterFieldRules(fieldRules));
            });
        }