天天看点

WPF窗体透明(只需三步)

窗体透明三步走(前两步必须添加,第三步可以设置背景透明也可以设置不透明度)

1.设置窗体无边框

public MainWindow()
        {
            InitializeComponent();
            this.WindowStyle = WindowStyle.None;//设置窗体无边框
        }
           
  1. 设置窗体支持透明度
public MainWindow()
        {
            InitializeComponent();
            this.WindowStyle = WindowStyle.None;//设置窗体无边框
            this.AllowsTransparency = true;//窗体支持透明度
        }
           
  1. 设置窗体不透明度
public MainWindow()
        {
            InitializeComponent();
            this.WindowStyle = WindowStyle.None;//设置窗体无边框
            this.AllowsTransparency = true;//窗体支持透明度
            this.Opacity = 0.6;//设置透明度为0.4
        }
           

效果图:

WPF窗体透明(只需三步)