WPF Window背景半透明 ,蒙版操作實現
阿新 • • 發佈:2018-11-01
本章主要講述:在WPF中,蒙版背景實現;
主要是通過改變Window的背景透明度和設定屬性(AllowsTransparency)允許透明,否則不生效;
XAML設計程式碼
<Window x:Class="Gvitech.Application.WPF.UI.FunFacility.WindowEquipmentRecord" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowEquipmentRecord" Height="300" Width="600" WindowStyle="None" WindowState="Normal" AllowsTransparency="True" > <!--設定Window 的背景顏色為半透明--> <Window.Background> <SolidColorBrush Opacity="0.6" Color="#001f55"></SolidColorBrush> </Window.Background> //或者通過改變Color的透明度 <Window.Background> <SolidColorBrush Color="#7F696969"/> </Window.Background> <Grid> <Button Content="Window 透明度測試"/> </Grid> </Window>
後臺程式碼
private void Window_Loaded(object sender, RoutedEventArgs e) { // 設定全屏 this.WindowState = System.Windows.WindowState.Normal;//不顯示邊框,只顯示工作區 this.WindowStyle = System.Windows.WindowStyle.None;//無邊框 this.ResizeMode = System.Windows.ResizeMode.NoResize;//禁止大小調整 ////this.Topmost = true;//設定視窗置於最頂層,不建議設定為置頂,切換擋住其他視窗 this. ShowInTaskBar=False;//是否顯示在工作列中 //WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;//居中顯示 //視窗全屏大小設定,通過傳入引數獲得主介面視窗大小,進行軟體介面大小蒙版,不是全屏覆蓋 this.Left = 0.0; this.Top = 0.0; this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;//獲取螢幕寬度大小 this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; }
效果圖