WPF应用ScalingWindow在客户电脑上显示透明的问题求助
WPF窗口显示异常问题求助
我使用WPF(基于.NET 5.0与MVVM模式)开发了一款应用,通过从Stack Overflow找到的OpenCloseWindowBehavior来打开三个不同窗口。公司所有电脑上运行正常,但客户电脑中的ScalingWindow出现以下问题:
- 打开后整个窗口透明,仅鼠标悬停到按钮、文本框时,这些控件才会显示
- 将窗口拖出屏幕边缘再拖回,显示可恢复正常
显示效果说明
- 正常显示:窗口所有控件完整呈现,布局正常
- 打开后异常:窗口整体透明,无可见控件
- 鼠标悬停后:仅被鼠标覆盖的按钮、文本框显示,其余区域仍透明
MainView代码
<i:Interaction.Behaviors> <local:OpenCloseWindowBehavior WindowType="local:CommunicationWindow" Open="{Binding IsCommunicationOpen, Mode=TwoWay}" Context="{Binding Communication}"/> <local:OpenCloseWindowBehavior WindowType="local:ScalingWindow" Open="{Binding IsScalingOpen, Mode=TwoWay}" Context="{Binding Scaling}"/> <local:OpenCloseWindowBehavior WindowType="local:AboutWindow" Open="{Binding IsAboutOpen, Mode=TwoWay}"/> </i:Interaction.Behaviors>
ViewModel代码
private CommunicationViewModel _communication; public CommunicationViewModel Communication { get => _communication; set => SetProperty(ref _communication, value); } private ScalingViewModel _scaling; public ScalingViewModel Scaling { get => _scaling; set => SetProperty(ref _scaling, value); } private bool _isCommunicationOpen; public bool IsCommunicationOpen { get => _isCommunicationOpen; set { if (value) { Communication = new(_measurementFlat.Connection); } else { Communication.Dispose(); Communication = null; } SetProperty(ref _isCommunicationOpen, value); } } private bool _isScalingOpen; public bool IsScalingOpen { get => _isScalingOpen; set { if (value) { Scaling = new(_measurementFlat.Scaling); } else { Scaling.Dispose(); Scaling = null; } SetProperty(ref _isScalingOpen, value); } } private bool _isAboutOpen; public bool IsAboutOpen { get => _isAboutOpen; set => SetProperty(ref _isAboutOpen, value); }
发布设置
采用独立部署模式,目标运行时为win-x64,勾选"生成单个文件",框架依赖版本选择.NET 5.0。
已尝试的解决方法
在窗口打开后调用window.InvalidateVisual()尝试刷新,但客户反馈无效果。目前无法复现该问题,不清楚故障原因,恳请提供解决方案,若有信息缺失请指出。
内容的提问来源于stack exchange,提问作者LuP1999
相关产品推荐
相关产品推荐

