protected static void OnIsActivePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { bool isActive = (bool)e.NewValue; FloatingControl me = d as FloatingControl; if (me != null) { bool isTaskbar = me is FloatingTaskbar; bool isDocked = (isTaskbar) ? ((me as FloatingTaskbar).DockPosition != DockPosition.NONE) : false; if (isActive) { me.Opacity = 1.0; if (!me.IsNailed && !isDocked) { Canvas.SetZIndex(me, CurrentZIndex++); } } else { me.Opacity = 0.75; Canvas.SetZIndex(me, (isTaskbar) ? 1 : 2); } me.OnIsActiveChanged(me, new IsActiveChangedEventArgs(isActive)); } }
/* ===================================================================== * If current window is activated, deactivate other floating controls * If current window is deactivated, activate the Taskbar or an expanded * window if Taskbar does not exist. Always set IsActive = false for a * window before set IsActive = true for another window * =====================================================================*/ protected void ResetActiveWindow(bool active) { if (ParentCanvas == null) { return; } if (active) { // Deactivate Other Windows if (ParentCanvas.Children.Count > 1) { foreach (FrameworkElement child in ParentCanvas.Children) { if (child is FloatingControl) { FloatingControl win = child as FloatingControl; if (win != this && win.IsActive) { win.IsActive = false; } } } } this.IsActive = true; } else { this.IsActive = false; // Activate Taskbar if Taskbar exists bool found = false; foreach (Control child in ParentCanvas.Children) { if (child is FloatingTaskbar) { FloatingTaskbar taskbar = child as FloatingTaskbar; taskbar.IsActive = true; taskbar.Focus(); found = true; break; } } // Activate an expanded window if (!found) { foreach (Control child in ParentCanvas.Children) { if (child is FloatingWindow) { FloatingWindow win = child as FloatingWindow; if (win != this && win.Visibility == Visibility.Visible && win.IsExpanded) { win.IsActive = true; win.Focus(); break; } } } } } }