using System.Windows; using System.Windows.Controls; namespace MultiTerm.Wpf.CustomControl; public class ExtendedTabControl : TabControl { public static readonly RoutedEvent AddButtonClickedEvent; #region Dotnet Properties /// /// .NET Property for /// public event RoutedEventHandler AddButtonClicked { add { this.AddHandler(AddButtonClickedEvent, value); } remove { this.RemoveHandler(AddButtonClickedEvent, value); } } #endregion static ExtendedTabControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedTabControl), new FrameworkPropertyMetadata(typeof(ExtendedTabControl))); AddButtonClickedEvent = EventManager.RegisterRoutedEvent("AddButtonClicked", RoutingStrategy.Bubble, typeof(RoutedEventArgs), typeof(ExtendedTabControl)); } public override void OnApplyTemplate() { base.OnApplyTemplate(); // get button from template if (GetTemplateChild("addButton") is Button button) { button.Click += OnAddButtonClicked; ; } } private void OnAddButtonClicked(object sender, RoutedEventArgs e) { RoutedEventArgs args = new(AddButtonClickedEvent); RaiseEvent(args); } }