private void On_tabItem_PreviewMouseButtonDown(object sender, MouseButtonEventArgs e) { if (this._suppressEvent) { return; } //如果发生事件的源头在 _tabControl 中的 TabItem var newItem = e.Source as TabItem; if (newItem != null && newItem.Parent == this._tabControl) { var oldItem = this._tabControl.SelectedItem as TabItem; if (oldItem != e.Source) { var deactiveWindow = GetWindow(oldItem); var activeWindow = GetWindow(newItem);; var args = new WorkspaceWindowActivingEventArgs(deactiveWindow, activeWindow); this.OnWindowActiving(args); if (args.Cancel) { e.Handled = true; } else { //由于在 Activing 事件中很可能会让 newItem 失去焦点(例如弹出窗口),所以需要重新让该页签获取焦点, //否则页签由于没有焦点,就不会发生 SelectedItemChanged 事件。 newItem.Focus(); } } } }
public bool TryActive(WorkspaceWindow window) { try { this._suppressEvent = true; TabItem newItem = GetTabItem(window.Title); if (newItem != null) { var oldItem = this._tabControl.SelectedItem as TabItem; if (oldItem == newItem) { return(true); } var args = new WorkspaceWindowActivingEventArgs(GetWindow(oldItem), window); this.OnWindowActiving(args); if (!args.Cancel) { this._tabControl.SelectedItem = newItem; this.OnWindowActived(args); return(true); } } return(false); } finally { this._suppressEvent = false; } }
private void OnWindowActiving(WorkspaceWindowActivingEventArgs e) { var handler = this.WindowActiving; if (handler != null) { handler(this, e); } }
private void On_tabItem_PreviewMouseButtonDown(object sender, MouseButtonEventArgs e) { if (this._suppressEvent) return; //如果发生事件的源头在 _tabControl 中的 TabItem var newItem = e.Source as TabItem; if (newItem != null && newItem.Parent == this._tabControl) { var oldItem = this._tabControl.SelectedItem as TabItem; if (oldItem != e.Source) { var deactiveWindow = GetWindow(oldItem); var activeWindow = GetWindow(newItem); ; var args = new WorkspaceWindowActivingEventArgs(deactiveWindow, activeWindow); this.OnWindowActiving(args); if (args.Cancel) { e.Handled = true; } else { //由于在 Activing 事件中很可能会让 newItem 失去焦点(例如弹出窗口),所以需要重新让该页签获取焦点, //否则页签由于没有焦点,就不会发生 SelectedItemChanged 事件。 newItem.Focus(); } } } }
private void OnWindowActiving(WorkspaceWindowActivingEventArgs e) { var handler = this.WindowActiving; if (handler != null) handler(this, e); }
public bool TryActive(WorkspaceWindow window) { try { this._suppressEvent = true; TabItem newItem = GetTabItem(window.Title); if (newItem != null) { var oldItem = this._tabControl.SelectedItem as TabItem; if (oldItem == newItem) { return true; } var args = new WorkspaceWindowActivingEventArgs(GetWindow(oldItem), window); this.OnWindowActiving(args); if (!args.Cancel) { this._tabControl.SelectedItem = newItem; this.OnWindowActived(args); return true; } } return false; } finally { this._suppressEvent = false; } }
void Workspace_WindowActiving(object sender, WorkspaceWindowActivingEventArgs e) { if (e.DeactiveWindow == this._ownerWindow) { this.SaveIfDirty(() => e.Cancel = true); } }