- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在设计一个 Window,但我注意到 WindowChrome 的这种奇怪行为(在 .NET FW 4.0 中,来自 external Microsoft.Windows.Shell dll)。
我将 WindowChrome 设置为 AllowTransparency = true 和 WindowStyle = None。
如果我设置 WindowChrome 的 ResizeBorderThickness <= 7 一切正常,但如果我这样做ResizeBorderThickness="8"
或更多,当窗口最大化时,我无法从屏幕顶部边缘附近的最后一个顶部像素拖动它,并且对于每个超过 7 的 +1,我必须开始从边缘向下拖动 1 个像素。
这很烦人,因为它在关闭窗口时禁用了常见行为,迫使我将其设置为 7 或更少。
有人可以向我解释这种行为吗?
谢谢!
最佳答案
窗口没有奇怪的行为。取而代之的是 窗口有两个奇怪的行为 .
"[...] when the Window is Maximized I can't drag it from the last top pixel near the top edge of the screen [...]"
<Trigger Property="WindowState" Value="Maximized">
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome ResizeBorderThickness="0" [...] />
</Setter.Value>
</Setter>
</Trigger>
"[...] If I set the WindowChrome's ResizeBorderThickness <= 7 everything works perfectly [...] and for each +1 exceeding 7 I must start dragging 1 pixel more down from the edge. [...]"
[DllImport("user32")]
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
[DllImport("user32")]
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
public class MONITORINFO
{
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
public RECT rcMonitor = new RECT();
public RECT rcWork = new RECT();
public int dwFlags = 0;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
public POINT(int x, int y) { this.x = x; this.y = y; }
}
[StructLayout(LayoutKind.Sequential)]
public struct MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
public static void CompatibilityMaximizedNoneWindow(Window window)
{
WindowInteropHelper wiHelper = new WindowInteropHelper(window);
System.IntPtr handle = wiHelper.Handle;
HwndSource.FromHwnd(handle).AddHook(
new HwndSourceHook(CompatibilityMaximizedNoneWindowProc));
}
private static System.IntPtr CompatibilityMaximizedNoneWindowProc(
System.IntPtr hwnd,
int msg,
System.IntPtr wParam,
System.IntPtr lParam,
ref bool handled)
{
switch (msg)
{
case 0x0024: // WM_GETMINMAXINFO
MINMAXINFO mmi =
(MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position
// to fit the work area of the correct monitor
// int MONITOR_DEFAULTTONEAREST = 0x00000002;
System.IntPtr monitor = MonitorFromWindow(hwnd, 0x00000002);
if (monitor != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x =
Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y =
Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x =
Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y =
Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
}
Marshal.StructureToPtr(mmi, lParam, true);
handled = true;
break;
}
return (System.IntPtr)0;
}
public MyWindow
{
[...]
MyNamespace.CompatibilityMaximizedNoneWindow(this);
}
关于wpf - WindowChrome ResizeBorderThickness 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19280016/
我正在设计一个 Window,但我注意到 WindowChrome 的这种奇怪行为(在 .NET FW 4.0 中,来自 external Microsoft.Windows.Shell dll)。
我是一名优秀的程序员,十分优秀!