本文整理汇总了C#中System.Windows.Window.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Window.Focus方法的具体用法?C# Window.Focus怎么用?C# Window.Focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Window
的用法示例。
在下文中一共展示了Window.Focus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QuickPlot
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();
});
}
示例2: PositionWindowToScreen
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();
}
示例3: Open
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();
}
示例4: BringToForeground
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;
}
示例5: ActivateForm
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);
}
}
示例6: ActivateWindow
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();
}
示例7: ActivateWindow
/// <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();
}
示例8: ShowSearchVoterWindow
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;
}
示例9: Show
/// <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();
}
示例10: BringToFront
private void BringToFront(Window window)
{
if (window.WindowState == WindowState.Minimized)
window.WindowState = WindowState.Normal;
window.Activate();
window.Topmost = true;
window.Topmost = false;
window.Focus();
}