WPF窗体透明Win7,Win10不同处理方法
直接上代码:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); WindowStyle = WindowStyle.None; if (IsWindows8x()) { ResizeMode = ResizeMode.CanMinimize; WindowChrome.SetWindowChrome(this, new WindowChrome { GlassFrameThickness = new Thickness(-1) }); } else { AllowsTransparency = true; } } bool IsWindows8x() { Version currentVersion = Environment.OSVersion.Version; Version tempVersion = new Version("6.2"); return currentVersion.CompareTo(tempVersion) >= 0; } }
然后给窗体设置背景颜色即可。