我需要使用 WindowStyle.None、AllowsTransparency = true 等创建一个自定义窗口。
其中一个要求是自定义 ResizeGrip 控件。
我使用 ResizeMode.CanResizeWithGrip 进行此操作,从此处找到的开源项目中获取一些代码: Fluid Kit
请参阅如果您有兴趣,请参加“GlassWindow”课程。
为了完成这项工作,我在 ResizeGrip 的 MouseLeftButtonDown 事件上调用以下代码:
NativeMethods.SendMessage(_interopHelper.Handle, WM.SYSCOMMAND, (IntPtr)((int)SC.SIZE + (int)sizingAction), IntPtr.Zero);
SizingAction 定义为:
enum SizingAction
{
West = 1,
East = 2,
North = 3,
NorthWest = 4,
NorthEast = 5,
South = 6,
SouthWest = 7,
SouthEast = 8,
}
一切正常,但当您通过西南(或任何左侧或顶部)调整大小时,我注意到一些奇怪的情况。您可以看到 WPF 窗口重绘以改变大小和位置(从顶部或左侧调整大小时总是会发生这种情况)。
如果您在具有默认窗口样式和调整大小模式的任何窗口上尝试此操作,它就可以正常工作。除 XP 外,您必须启用经典主题。
有谁知道使用这个的替代方法?或者有办法解决吗?
我还在 MSDN 论坛上发布了一些信息: MSDN 论坛
PS - 如果有人想要 svn checkout Fluid Kit 并通过在其示例项目中设置 StartupUri="GlassWindow/Window1.xaml" 来运行 GlassWindow 示例,您可以直接看到此行为。
编辑:微软告诉我发送产品建议...
如果有人有类似的问题,链接位于此处:
产品建议
如果您想亲自尝试一下,我还在这里举了一个示例:
示例
I am needing to make a custom window with WindowStyle.None, AllowsTransparency = true, etc.
One requirement is a custom ResizeGrip control.
I have this working with ResizeMode.CanResizeWithGrip, taking some code from an open source project found here: Fluid Kit
See the "GlassWindow" class if you're interested.
To do the work, I'm calling the following code on the MouseLeftButtonDown event of the ResizeGrip:
NativeMethods.SendMessage(_interopHelper.Handle, WM.SYSCOMMAND, (IntPtr)((int)SC.SIZE + (int)sizingAction), IntPtr.Zero);
SizingAction is defined as:
enum SizingAction
{
West = 1,
East = 2,
North = 3,
NorthWest = 4,
NorthEast = 5,
South = 6,
SouthWest = 7,
SouthEast = 8,
}
It is all working, but I notice some strangeness when you resize via a SouthWest (or any left or top) side. You are able to see the WPF window redraw for both a size and position change (which always occurs when resizing from the top or left).
If you try this on any window with the default window style and resize mode, it works just fine. With the exception of XP, you have to have the classic theme on.
Does anyone know an alternative to using this? Or a way to fix it?
I also posted some information on MSDN forums, here: MSDN Forums
PS - You can see this behavior first hand if someone wants to svn checkout Fluid Kit and run the GlassWindow example by setting StartupUri="GlassWindow/Window1.xaml" in their example project.
EDIT: Microsoft told me to send a product suggestion...
The link is here if anyone has a similar problem:
Product Suggestions
I also put an example here if you would like to try it first hand:
Sample
发布评论
评论(1)
Microsoft 报告所有 WPF 窗口都会发生这种情况。
标准样式之所以有效,是因为窗口将呈现标题栏、窗口边框等。调整标准边框窗口的大小时,您可以看到 WPF 客户区在任何计算机上闪烁。
如果将 WindowStyle 设置为 None,则 WPF 将渲染整个窗口,因此这种闪烁会变得更加明显,因为整个窗口都会闪烁。
目前,解决方法是将窗口设置为固定大小并调整客户区域的大小。然而,这对性能要求很高——所以你最好忍受闪烁。
您可以点击我上面的链接查看我的产品建议,看看微软是否会解决这个问题。如果您有类似问题,请投票。
Microsoft reports this happens to all WPF-windows.
Standard styles work because windows will render the title bar, window border, etc. When resizing a standard-bordered window, you can see the WPF client area flicker on any machine.
If you set WindowStyle to None, then WPF is rendering the entire window and so this flickering becomes more noticeable since the entire window flickers.
For now, the workaround is to make your window a fixed size and resize the client area. However, this is pretty performance intensive--so you might be better off to live with flickering.
You can follow my link above to my product suggestion to see if Microsoft is ever going to fix this. Please vote for it if you have a similar issue.