using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using WPFProject.Events; using WPFProject.UI; using WPFProject.Utils; 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 IconTabItem _SelectedItem; public IconTabItem SelectedItem { get { return _SelectedItem; } set => RaiseAndSetIfChanged(ref _SelectedItem, 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="123", Content = plugin }, new IconTabItem(){ Header="321" }, }; } 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; } } } }