wenxiangchao
2026-11-02 fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using HMI.Core.Api;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
 
namespace WPFProject.Controls
{
    /// <summary>
    /// MenuTabControl.xaml 的交互逻辑
    /// </summary>
    public partial class MenuTabControl : UserControl, INotifyPropertyChanged
    {
        public virtual event PropertyChangedEventHandler PropertyChanged;
 
        protected virtual void RaisePropertyChanged(string name)
        {
 
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
 
        protected void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
        {
            old = @new;
            if (propertyName != null)
            {
                RaisePropertyChanged(propertyName);
            }
        }
 
        private Visibility ItemVisibility = Visibility.Collapsed;
 
        //public event EventHandler ClassHandlerProcessed;
        //public static void CustomClickClassHandler(object sender, RoutedEventArgs e)
        //{
        //    MenuTabControl simpleBtn = sender as MenuTabControl;
        //    EventArgs args = new EventArgs();
        //    simpleBtn.ClassHandlerProcessed(simpleBtn, args);
        //}
 
 
        // Tab切换事件
        public static readonly RoutedEvent OnTabChangeEvent =
             EventManager.RegisterRoutedEvent("OnTabChange", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MenuTabControl));
 
        public event RoutedEventHandler OnTabChange
        {
            add
            {
                AddHandler(OnTabChangeEvent, value);
            }
 
            remove
            {
                RemoveHandler(OnTabChangeEvent, value);
            }
        }
 
 
 
        private ObservableCollection<IconTabItem> _Items;
 
        public ObservableCollection<IconTabItem> Items
        {
            get { return _Items; }
            set => RaiseAndSetIfChanged(ref _Items, value);
        }
 
        private ObservableCollection<IconTabItem> _Items_Level2;
 
        public ObservableCollection<IconTabItem> Items_Level2
        {
            get { return _Items_Level2; }
            set => RaiseAndSetIfChanged(ref _Items_Level2, value);
        }
 
        private IconTabItem _TabSelectedItem;
 
        public IconTabItem TabSelectedItem
        {
            get { return _TabSelectedItem; }
            set => RaiseAndSetIfChanged(ref _TabSelectedItem, value);
        }
 
 
        private Visibility _ShowMenu;
 
        public Visibility ShowMenu
        {
            get { return _ShowMenu; }
            set => RaiseAndSetIfChanged(ref _ShowMenu, value);
        }
 
        private event EventHandler<SelectionChangedEventArgs> ChildTabChanged;
 
 
        public MenuTabControl()
        {
            //IPlugin plugin = new WorkControl();
            //ChildTabChanged += plugin.OnTabChange;
 
            //DataContext = this;
            //InitializeComponent();
            //Items = new ObservableCollection<IconTabItem> {
            //new IconTabItem(){
            //    Header="111",
            //    Children = new ObservableCollection<IconTabItem>{
            //        new IconTabItem(){
            //            Header = "112",
            //            Content = plugin
            //        }
            //    }
            //},
            //new IconTabItem(){
            //    Header="222",
            //    Children = new ObservableCollection<IconTabItem>()
            //}
            //};
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // SetItemVisibility();
            //Window main = Window.GetWindow(this);
            //foreach (IconTabItem item in Items)
            //{
            //    if (item.Body != null)
            //    {
            //        Win32Helper.SetParentForWPF(item.Body, main);
            //    }
            //}
        }
 
        private void tabLevel_1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChildTabChanged?.Invoke(this, e);
            RoutedEventArgs ee = new RoutedEventArgs(OnTabChangeEvent);
            RaiseEvent(ee);
        }
 
        public void ChangeItemVisibility()
        {
            ItemVisibility = ItemVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
            SetItemVisibility();
        }
 
        private void SetItemVisibility()
        {
            if (Items == null)
            {
                return;
            }
            foreach (IconTabItem item in Items)
            {
                item.Visibility = ItemVisibility;
                if (item.Children != null)
                {
                    foreach (var child in item.Children)
                    {
                        child.Visibility = ItemVisibility;
                    }
                }
            }
        }
    }
}