chr
2025-03-04 3f62d18e4361cd1d7a49c126765d95b2ad9c8246
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls.WebParts;
using System.Windows;
using System.Windows.Interop;
 
namespace PdmSwPlugin.Common.Util.UI
{
    /// <summary>
    /// MultiExWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MultiExWindow : Window, INotifyPropertyChanged
    {
        #region ...
        public virtual event PropertyChangedEventHandler PropertyChanged;
 
        public virtual void RaisePropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
 
        public void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
        {
            old = @new;
            if (propertyName != null)
            {
                RaisePropertyChanged(propertyName);
            }
        }
        #endregion
 
        // Windows API 函数
        [DllImport("user32.dll", SetLastError = true)]
        private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
 
        [DllImport("user32.dll", SetLastError = true)]
        private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 
        private const int GWL_STYLE = -16;  // 窗口样式
        private const int WS_MINIMIZEBOX = 0x00020000;  // 最小化按钮样式
 
        private string _title;
        public string title
        {
            get => _title;
            set => RaiseAndSetIfChanged(ref _title, value);
        }
 
        private string _header;
        public string header
        {
            get => _header;
            set => RaiseAndSetIfChanged(ref _header, value);
        }
 
        private ObservableCollection<string> _exceptions;
 
        public ObservableCollection<string> exceptions
        {
            get => _exceptions;
            set => RaiseAndSetIfChanged(ref _exceptions, value);
        }
 
 
        public MultiExWindow(DependencyObject parent, string title, List<string> exceptions,string header = "异常信息")
        {
            this.title = title;
            this.header = header;
            InitializeComponent();
            DataContext = this;
            table.Columns[0].Header = header;
            if (exceptions == null)
            {
                this.exceptions = new ObservableCollection<string>();
            }
            else
            {
                this.exceptions = new ObservableCollection<string>(exceptions);
            }
            Owner = Window.GetWindow(parent);
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 获取窗口句柄
            IntPtr hWnd = new WindowInteropHelper(this).Handle;
 
            // 获取当前窗口的样式
            int currentStyle = GetWindowLong(hWnd, GWL_STYLE);
 
            // 移除最小化按钮
            SetWindowLong(hWnd, GWL_STYLE, currentStyle & ~WS_MINIMIZEBOX);
            Dispatcher.Invoke(() =>
            {
                table.ItemsSource = new ObservableCollection<string>(exceptions);
            });
        }
    }
}