X3

RedSky

导航

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;
        }
    }

 

然后给窗体设置背景颜色即可。

posted on 2021-06-24 18:01  HotSky  阅读(245)  评论(0编辑  收藏  举报