public override void OnApplyTemplate() {
base.OnApplyTemplate();
// wire up the CloseButton's Click event if the button exists
ButtonBase button = this.Template.FindName("PART_CloseButton", this) as ButtonBase;
if (button != null) {
button.PreviewMouseLeftButtonDown += (sender, e) => {
// get the parent tabcontrol
TabControl tc = Helper.FindParentControl<TabControl>(this);
if (tc == null)
return;
// remove this tabitem from the parent tabcontrol
tc.RemoveTabItem(this);
};
}
this.PreviewMouseLeftButtonUp += TabItem_PreviewMouseLeftButtonUp;
this.PreviewMouseDoubleClick += TabItem_PreviewMouseDoubleClick;
this.MouseRightButtonUp += TabItem_MouseRightButtonUp;
}