WPF透明边框导致UI停止重绘 [英] WPF transparent borders causes the UI to stop redrawing

查看:42
本文介绍了WPF透明边框导致UI停止重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为对我之前的问题的跟进,我是想知道如何正确使用透明窗口.如果我将窗口设置为使用透明度,UI 有时会停止响应.实际发生的情况是 UI 没有按应有的方式更新.不出现动画,页面似乎不导航;但是,如果您观看调试器单击按钮、链接等......确实可以工作.最小化和恢复窗口再次赶上"用户界面,用户可以继续工作,直到行为恢复.

As a follow up to my previous question, I am wondering how to use transparent windows correctly. If I have set my window to use transparency, the UI will occasionally appear to stop responding. What is actually happening is that the UI simply is not updating as it should. Animations do not occur, pages do not appear to navigate; however, if you watch the debugger clicking on buttons, links, etc.. do actually work. Minimizing and restoring the window "catches up" the UI again and the user can continue working until the behavior comes back.

如果我删除透明边框,则不会发生该行为.我是不是做错了什么,还是有其他一些设置、代码等……我需要实施这些设置才能正确使用透明边框?

If I remove the transparent borders, the behavior does not occur. Am I doing something wrong or is there some other setting, code, etc... that I need to implement to work with transparent borders properly?

这是我对失败代码的窗口声明.

Here is my window declaration for the code that fails.

<Window x:Class="MyProject.MainContainer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF APplication" Height="600" Width="800"    
    xmlns:egc="ControlLibrary" Background="{x:Null}"
    BorderThickness="0"
    AllowsTransparency="True"
    MinHeight="300" MinWidth="400" WindowStyle="None" >

以及没有表现出行为的代码

And the code that does not exhibit the behavior

<Window x:Class="MyProject.MainContainer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF Application" Height="600" Width="800"    
    xmlns:egc="ControlLibrary" Background="{x:Null}"
    BorderThickness="0"
    AllowsTransparency="False"
    MinHeight="300" MinWidth="400" WindowStyle="None" >

推荐答案

我想我终于找到了解决方法.从我读过的所有内容来看,XP SP3 & 不应该出现这个问题..NET 3.5 SP1,但它是.

I think that I've finally found a workaround. From everything I've read this problem should not be occurring with XP SP3 & .NET 3.5 SP1, but it is.

这篇博文中的示例 展示了如何使用 Win32 API 函数来创建不规则形状的窗口,这就是我正在做的.在重新设计主窗口以使用这些技术后,事情似乎按预期工作,行为没有恢复.

The example from this blog post shows how to use the Win32 API functions to create an irregular shaped window, which is what I"m doing. After reworking my main window to use these techniques, things seem to be working as expected and the behavior has not returned.

还需要注意的是,作者之所以推荐这种方法,是因为 WPF 和透明窗口的性能问题.虽然我相信在 .NET 3.5 SP1 中它可能会更好,但这并不难实现并且应该表现得更好.

It is also of note that the reason the author recommends this method is due to performance issues with WPF and transparent windows. While I believe it may be better in .NET 3.5 SP1 that it was, this was not that hard to implement and should perform better.

这篇关于WPF透明边框导致UI停止重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆