Example #1
0
 /// <summary>
 /// Remove Blur Effects
 /// </summary>
 /// <param name=”win”></param>
 public static void ClearEffect(this System.Windows.Window win)
 {
     // Back changed effective objects
     win.Dispatcher.Invoke(new Action(delegate { win.Effect = effectBuffer; }), System.Windows.Threading.DispatcherPriority.Normal);
     win.Dispatcher.Invoke(new Action(delegate { win.OpacityMask = brushBuffer; }), System.Windows.Threading.DispatcherPriority.Normal);
     win.Dispatcher.Invoke(new Action(delegate { win.Focus(); }), System.Windows.Threading.DispatcherPriority.Normal);
 }
 public static void QuickPlot(double[] x, double[] y, 
     Tuple<double, double> xRange = null, Tuple<double, double> yRange = null)
 {
     PlotHelper.Dispatcher.Invoke(() =>
     {
         var window = new Window()
         {
             Width = 640,
             Height = 480
         };
         var plotControl = new PlotControl();
         plotControl.AddLine(
             x.Zip(y, (a, b) => new OxyPlot.DataPoint(a, b))
             .ToArray());
         if (xRange != null)
         {
             var xAxis = plotControl.Plot.Axes.First();
             xAxis.Minimum = xRange.Item1;
             xAxis.Maximum = xRange.Item2;
         }
         window.Content = plotControl;
         window.Title = "Plot Window";
         window.Show();
         window.Focus();
         window.BringIntoView();
         window.InvalidateVisual();
     });
 }
Example #3
0
 private void PositionWindowToScreen(Window window, Screen screen)
 {
     window.WindowStartupLocation = WindowStartupLocation.Manual;
     window.Left = screen.WorkingArea.Left;
     window.Top = screen.WorkingArea.Top;
     window.Width = screen.WorkingArea.Width;
     window.Height = screen.WorkingArea.Height;
     window.Show();
     window.WindowState = WindowState.Maximized;
     window.Focus();
 }
Example #4
0
        public FileDialogs(System.Windows.Window window)
        {
            _window     = window;
            _dispatcher = _window == null
                                ? System.Windows.Application.Current.Dispatcher
                                : _window.Dispatcher;

            _focus = _window == null
                                ? new Action(() => { })
                                : (() => _window.Focus());
        }
Example #5
0
        public static void FocusWindow(System.Windows.Window win)
        {
            if (win.WindowState == WindowState.Minimized)
            {
                win.WindowState = WindowState.Normal;
            }

            win.Activate();
            win.Topmost = true;  // important
            win.Topmost = false; // important
            win.Focus();         // important
        }
        public void Open(string title, object dataContext, Action callback)
        {
            var window = new Window();

            window.Title = title;
            window.DataContext = dataContext;
            window.Content = dataContext;
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.ResizeMode = ResizeMode.NoResize;
            window.Topmost = true;
            window.SizeToContent = SizeToContent.WidthAndHeight;
            window.Closing += (s, e) => { callback?.Invoke(); };
            window.Show();
            window.Focus();
        }
        public static void BringToForeground(Window mainWindow)
        {
            if (mainWindow.WindowState == WindowState.Minimized || mainWindow.Visibility == Visibility.Hidden)
            {
                mainWindow.Show();
                mainWindow.WindowState = WindowState.Normal;
            }

            // According to some sources these steps gurantee that an app will be brought to foreground.
            mainWindow.Activate();
            mainWindow.Topmost = true;
            mainWindow.Topmost = false;
            mainWindow.Focus();
            mainWindow.ShowInTaskbar = true;
        }
		public override void ActivateForm(Window form, Window window, IntPtr hwnd) {
			var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
			var wHandle = (PresentationSource.FromVisual(window) as HwndSource).Handle;
			if (window == null || wHandle != fHandle)
			{

				form.Topmost = true;
				form.Topmost = false;
				form.Focus();
				form.Show();
				form.Activate();

				// stop flashing...happens occassionally when switching quickly when activate manuver is fails
				Shell32.FlashWindow(fHandle, 0);
			}
		}
Example #9
0
        private void ActivateWindow(Window window)
        {
            if (!window.IsVisible)
            {
                window.Show();
            }

            if (window.WindowState == WindowState.Minimized)
            {
                window.WindowState = WindowState.Normal;
            }

            window.Activate();
            window.Topmost = true;  
            window.Topmost = false; 
            window.Focus();      
        }
        /// <summary>
        ///     This function is the callback used to execute the command when the menu item is clicked.
        ///     See the constructor to see how the menu item is associated with this function using
        ///     OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            if (_definitionWindow != null)
            {
                _definitionWindow.Focus();
                _definitionWindow.Show();
                return;
            }
            Window         window         = new Window();
            DefinitionPage definitionPage = new DefinitionPage();

            definitionPage.Closing += (_s, _e) =>
            {
                window.Close();
                _definitionWindow = null;
            };
            window.Closed += (_s, _e) => { _definitionWindow = null; };
            window.Title   = "编码规范工具设置";
            window.Content = definitionPage;
            window.Show();

            _definitionWindow = window;
        }
        private void ConformWindow(string file, List <string> project)
        {
            if (_conformWindow != null)
            {
                _conformWindow.Focus();
                _conformWindow.Show();
                return;
            }

            string folder = "";

            if (!string.IsNullOrEmpty(file))
            {
                folder = new FileInfo(file).Directory?.FullName;
            }
            Window window = new Window()
            {
                Width  = 500,
                Height = 500
            };
            ConformPage conformPage = new ConformPage();

            window.Content       = conformPage;
            window.Title         = "编码规范工具";
            conformPage.Closing += (_s, _e) =>
            {
                window.Close();
                _conformWindow = null;
            };
            window.Closed += (_s, _e) => { _conformWindow = null; };
            conformPage.SolutionFolder = folder;
            conformPage.Project        = project;
            window.Show();
            conformPage.InspectFolderEncoding();
            _conformWindow = window;
        }
        /// <summary>
        /// Activates the window and makes sure the window is in the foreground.
        /// </summary>
        /// <param name="window">The window. Can be <see langword="null"/>.</param>
        /// <remarks>
        /// The method <see cref="Window.Activate"/> of the <see cref="Window"/> class should 
        /// activate a window and bring it to the foreground. However, this does not always work.
        /// Sometimes the application icon in the task bar flashes, but the windows stays inactive.
        /// This method uses a few tricks to make sure that the window lands in the foreground.
        /// </remarks>
        public static void ActivateWindow(Window window)
        {
            if (window == null)
                return;

            // Bring application to foreground:
            // Calling Window.Activate() immediately or deferred using Dispatcher.BeginInvoke 
            // does not work. The icon in the task bar flashes, but the windows stays inactive.
            //_shell.Window.Activate();
            //_shell.Window.Dispatcher.BeginInvoke(new Action(() => _shell.Window.Activate()));
            // Following calls should make sure that the window lands in the foreground:
            // (from http://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf)
            if (!window.IsVisible)
                window.Show();

            if (window.WindowState == WindowState.Minimized)
                window.WindowState = WindowState.Normal;

            window.Activate();
            window.Topmost = true;
            window.Topmost = false;
            window.Focus();
        }
 private void ShowSearchVoterWindow()
 {
     if (_currentSearchWindow != null)
     {
         _currentSearchWindow.Focus();
         return;
     }
     var win = new Window();
     win.Content = _searchView;
     win.Closed += (s, e) =>
     {
         ((Window)s).Content = null;
         _currentSearchWindow = null;
         _searchController.Clear();
     };
     win.Height = _searchView.Height + 30;
     win.Width = _searchView.Width + 10;
     win.ResizeMode = ResizeMode.NoResize;
     win.Show();
     win.LostFocus += (s, e) => win.Focus(); //Force focus
     _currentSearchWindow = win;
 }
 /// <summary>
 /// Shows a message window, focusing on the parent after creation.
 /// </summary>
 /// <param name="message">Message to display</param>
 /// <param name="duration">Amount of time, in milliseconds, to show the window</param>
 /// <param name="parent">Window to send focus to</param>
 public static void Show(String message, double duration, Window parent)
 {
     MessageWindow w = new MessageWindow(message, duration);
     w.Show();
     parent.Focus();
 }
Example #15
0
    private void BringToFront(Window window)
    {
      if (window.WindowState == WindowState.Minimized)
        window.WindowState = WindowState.Normal;

      window.Activate();
      window.Topmost = true;
      window.Topmost = false;
      window.Focus();
    }