Avalonia Winodw 半透明視窗(overlayWindow) 控制每次只顯示一個(之前的先隱藏) 避免背景太黑
Avalonia Winodw 半透明視窗(overlayWindow) 控制每次只顯示一個(之前的先隱藏) 避免背景太黑
資料來源: 自己
code
using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Controls.Templates; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media; using System.Threading.Tasks; using VPOS; using VPOS_Avalonia.ViewModels; using VPOS_Avalonia.Views; namespace VPOS_Avalonia; public partial class DevicesList : Window { private Devices[] m_Devices; public static bool m_blnRun = false; public static int m_intDeviceSID = -1; private OverlayWindow m_OverlayWindow = null; public DevicesList(OverlayWindow overlayWindow) { ExternalPopup.devicesList = this;//6 //隱藏工具列 this.ExtendClientAreaToDecorationsHint = true; this.ExtendClientAreaTitleBarHeightHint = -1; this.SystemDecorations = SystemDecorations.None; //---隱藏工具列 WindowStartupLocation = WindowStartupLocation.CenterScreen;//視窗置中 this.Background = new SolidColorBrush(Color.Parse("#ff194a6e"));//設定背景色 this.WindowState = WindowState.Maximized;//視窗最大化非滿版 InitializeComponent(); FullGrid.IsVisible = false; m_OverlayWindow = overlayWindow; m_blnRun = false; int intDevicesCount = -1; intDevicesCount = SQLDataTableModel.m_printer_valueList.Count; m_Devices = new Devices[intDevicesCount - 1];//建立按鈕陣列 int intColumns = 2; int intRows = (intDevicesCount - 1) / intColumns + ((intDevicesCount - 1) % intColumns == 0 ? 0 : 1); for (int i = 0; i < intRows; i++) { BodyGrid.RowDefinitions.Add(new RowDefinition(new GridLength(340, GridUnitType.Pixel))); } for (int i = 0; i < intColumns; i++) { BodyGrid.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(2,GridUnitType.Star))); } SetLab01();//設定錢箱連線資訊 for (int i = 0; i < (intDevicesCount - 1); i++) { m_Devices[i] = new Devices(SQLDataTableModel.m_printer_valueList[i + 1].SID);//建立每個按鈕實體 int intRow = i / intColumns; int intColumn = i % intColumns; m_Devices[i].Margin = new Thickness(5); m_Devices[i].ExternalClicked += DeviceEdit_Show; Grid.SetRow(m_Devices[i], intRow); Grid.SetColumn(m_Devices[i], intColumn); BodyGrid.Children.Add(m_Devices[i]); } } public void Window_Loaded(object sender, RoutedEventArgs e) { FullGrid.IsVisible = true; ConfigureButtonStyle(CloseBtn); } private void CloseBtn_Clicked(object sender, RoutedEventArgs e) { Close(); } private async void Edit_Clicked(object sender, RoutedEventArgs e) { m_intDeviceSID = 0; await DeviceEdit_Show(); SetLab01();//設定錢箱連線資訊 m_intDeviceSID = -1; } private async void DeviceEdit_Show(object sender, RoutedEventArgs e) { await DeviceEdit_Show(); for (int i = 0; i < m_Devices.Length; i++) { if(m_Devices[i].m_intSID == m_intDeviceSID) { m_Devices[i].SetUI(); break; } } m_intDeviceSID = -1; } private async Task DeviceEdit_Show() { //--- //隱藏原本遮罩 Owner = null; m_OverlayWindow.Hide(); //--- //--- //顯示編輯畫面和對應遮罩 OverlayWindow _overlay = new OverlayWindow(); DeviceEdit DeviceEditBuf = new DeviceEdit(m_intDeviceSID); DeviceEditBuf.Topmost = true; _overlay.ShowDialog(this); await DeviceEditBuf.ShowDialog(_overlay); _overlay.Close(); //---顯示編輯畫面和對應遮罩 //--- //顯示原本遮罩 Owner = m_OverlayWindow; m_OverlayWindow.Show(); //---顯示原本遮罩 } private void ConfigureButtonStyle(Button button)//Avalonia 使用程式碼方式當 滑鼠移動到Button 上方 停用 Button背景顏色變化 保持 原本背景色和文字顏色(by ChatGPT) { // 定義自訂模板來移除 PointerOver 狀態的影響 button.Template = new FuncControlTemplate<Button>((control, _) => { return new Border { [!Border.BackgroundProperty] = control[!Button.BackgroundProperty], // 綁定按鈕的背景屬性 Child = new ContentPresenter { [!ContentPresenter.ContentProperty] = control[!Button.ContentProperty], // 綁定按鈕的內容 [!ContentPresenter.ForegroundProperty] = control[!Button.ForegroundProperty], // 綁定文字顏色 [!ContentPresenter.HorizontalAlignmentProperty] = control[!Button.HorizontalContentAlignmentProperty], [!ContentPresenter.VerticalAlignmentProperty] = control[!Button.VerticalContentAlignmentProperty] } }; }); } private void SetLab01()//設定錢箱連線資訊 { if (SQLDataTableModel.m_printer_valueList[0].printer_config_value.on_off_state == "N") { Lab01.Text = "錢箱綁定方式: [未啟用]"; } else { Lab01.Text = $"錢箱綁定方式: [{SQLDataTableModel.m_printer_valueList[0].printer_config_value.cash_box_type}] >>> [{SQLDataTableModel.m_printer_valueList[0].printer_config_value.device_model}]"; } } }