简体   繁体   English

C#WPF-自定义大小调整

[英]C# WPF - custom resizing

I am needing to make a custom window with WindowStyle.None, AllowsTransparency = true, etc. 我需要使用WindowStyle.None,AllowsTransparency = true等创建自定义窗口。

One requirement is a custom ResizeGrip control. 一个要求是自定义ResizeGrip控件。

I have this working with ResizeMode.CanResizeWithGrip, taking some code from an open source project found here: Fluid Kit 我使用ResizeMode.CanResizeWithGrip进行此工作,并从此处的开源项目中获取了一些代码: Fluid Kit

See the "GlassWindow" class if you're interested. 如果您有兴趣,请参阅“ GlassWindow”类。

To do the work, I'm calling the following code on the MouseLeftButtonDown event of the ResizeGrip: 为此,我在ResizeGrip的MouseLeftButtonDown事件上调用以下代码:

NativeMethods.SendMessage(_interopHelper.Handle, WM.SYSCOMMAND, (IntPtr)((int)SC.SIZE + (int)sizingAction), IntPtr.Zero);

SizingAction is defined as: SizingAction定义为:

    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). 您可以看到WPF窗口重新绘制了尺寸和位置的变化(从顶部或左侧调整大小时总是发生这种情况)。

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. 除XP外,您必须启用经典主题。

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 我还在MSDN论坛上发布了一些信息,在这里: MSDN论坛

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. PS-如果有人要svn检出Fluid Kit并通过在示例项目中设置StartupUri =“ GlassWindow / Window1.xaml”来运行GlassWindow示例,则可以直接看到此行为。

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 样品

Microsoft reports this happens to all WPF-windows. Microsoft报告所有WPF窗口都会发生这种情况。

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. 标准样式之所以起作用,是因为窗口会渲染标题栏,窗口边框等。调整标准边框窗口的大小时,您可以在任何计算机上看到WPF客户区闪烁。

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. 如果将WindowStyle设置为None,则WPF会渲染整个窗口,因此由于整个窗口闪烁,这种闪烁变得更加明显。

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. 您可以点击上面的链接到我的产品建议,以查看Microsoft是否打算解决此问题。 Please vote for it if you have a similar issue. 如果您有类似的问题,请投票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM