本文整理汇总了C#中Window.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Window.GetType方法的具体用法?C# Window.GetType怎么用?C# Window.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Window
的用法示例。
在下文中一共展示了Window.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetOwnerWindow
/// <summary>
/// Sets the owner window of a specific window. It will first try to set the owner via
/// the <paramref name="ownerWindow"/>. If the <paramref name="ownerWindow"/> is not available,
/// this method will use the <paramref name="ownerHandle"/> to set the parent.
/// </summary>
/// <param name="window">Reference to the current window.</param>
/// <param name="ownerWindow">New owner window.</param>
/// <param name="ownerHandle">The owner handle.</param>
/// <param name="forceNewOwner">If true, the new owner will be forced. Otherwise, if the
/// window currently has an owner, that owner will be respected (and thus not changed).</param>
/// <param name="focusFirstControl">If true, the first control will automatically be focused.</param>
private static void SetOwnerWindow(Window window, Window ownerWindow, IntPtr ownerHandle, bool forceNewOwner, bool focusFirstControl)
{
if (focusFirstControl)
{
window.FocusFirstControl();
}
if (!forceNewOwner && HasOwner(window))
{
return;
}
if (ownerWindow != null)
{
if (ownerWindow == window)
{
Log.Warning("Cannot set owner window to itself, no owner window set");
return;
}
if (window.Dispatcher.GetThreadId() != ownerWindow.Dispatcher.GetThreadId())
{
Log.Warning("The owner window '{0}' is not created on the same thread as the current window '{1}', cannot set owner window",
ownerWindow.GetType().GetSafeFullName(), window.GetType().GetSafeFullName());
return;
}
window.Owner = ownerWindow;
}
else
{
// Set owner via interop helper
var interopHelper = new WindowInteropHelper(window);
interopHelper.Owner = ownerHandle;
// Get handler (so we can nicely unsubscribe)
RoutedEventHandler onWindowLoaded = null;
onWindowLoaded = delegate(object sender, RoutedEventArgs e)
{
// Since this owner type doesn't support WindowStartupLocation.CenterOwner, do
// it manually
if (window.WindowStartupLocation == WindowStartupLocation.CenterOwner)
{
// Get the parent window rect
RECT ownerRect;
if (GetWindowRect(ownerHandle, out ownerRect))
{
// Get some additional information
int ownerWidth = ownerRect.Right - ownerRect.Left;
int ownerHeight = ownerRect.Bottom - ownerRect.Top;
int ownerHorizontalCenter = (ownerWidth / 2) + ownerRect.Left;
int ownerVerticalCenter = (ownerHeight / 2) + ownerRect.Top;
// Set the location to manual
window.WindowStartupLocation = WindowStartupLocation.Manual;
// Now we know the location of the parent, center the window
window.Left = ownerHorizontalCenter - (window.ActualWidth / 2);
window.Top = ownerVerticalCenter - (window.ActualHeight / 2);
}
}
((Window)sender).Loaded -= onWindowLoaded;
};
window.Loaded += onWindowLoaded;
}
}
示例2: Show
//Channel music;
void Show(Window w)
{
if (CurrentWindow != null)
{
CurrentWindow.Close();
if (w.GetType() == CurrentWindow.GetType())
{
CurrentWindow = null;
return;
}
}
CurrentWindow = w;
Add(w, 0, 1);
Layout.Update(Size);
}