using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using HMI.Core.Api; using WPFProject.UI; namespace WPFProject.Controls { /// /// MenuTabControl.xaml 的交互逻辑 /// 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(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 _Items; public ObservableCollection Items { get { return _Items; } set => RaiseAndSetIfChanged(ref _Items, value); } private ObservableCollection _Items_Level2; public ObservableCollection 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 ChildTabChanged; public MenuTabControl() { IPlugin plugin = new WorkControl(); ChildTabChanged += plugin.OnTabChange; DataContext = this; InitializeComponent(); Items = new ObservableCollection { new IconTabItem(){ Header="111", Children = new ObservableCollection{ new IconTabItem(){ Header = "112", Content = plugin } } }, new IconTabItem(){ Header="222", Children = new ObservableCollection() } }; } 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; } } } } } }