alielie
2025-10-10 15bbd62b0b24b72c717ae91ab45348a2083ad04e
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
 
using System.Windows;
using System.Windows.Controls;
 
namespace HMI.UI
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BaseWindowTemplate
    {
        void Min_Click(object sender, RoutedEventArgs e)
        {
            Window.GetWindow(sender as FrameworkElement).WindowState = WindowState.Minimized;
        }
 
        void Max_Click(object sender, RoutedEventArgs e)
        {
            var temp = Window.GetWindow(sender as FrameworkElement).WindowState;
            Window.GetWindow(sender as FrameworkElement).WindowState = temp == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }
 
        void Close_Click(object sender, RoutedEventArgs e)
        {
            Window.GetWindow(sender as FrameworkElement).Close();
        }
    }
 
    public partial class BaseWindow : Window
    {
        public void AddButton(Button button)
        {
            var panelsda = Template.FindName("RightPanel", this);
            var panel = (StackPanel)this.Template.FindName("RightPanel", this);
            panel?.Children.Add(button);
        }
 
        public void InsertButton(Button button,int index)
        {
            var panelsda = Template.FindName("RightPanel", this);
            var panel = (StackPanel)this.Template.FindName("RightPanel", this);
            panel?.Children.Insert(index, button);
        }
    }
}