private static void window_Closed(object sender, EventArgs e) { Func <UIElement, bool> predicate = null; Window w = (Window)sender; w.HideWindow.Begin(); WindowList.Remove(w.ID); desktop.Children.Remove(w); if (desktop.Children.Count == 0) { countItem = 0; } if (taskBar != null) { if (predicate == null) { predicate = delegate(UIElement i) { return((i is TaskBarItem) && (((TaskBarItem)i).Name == ("tb" + w.Name))); }; } TaskBarItem item = (TaskBarItem)taskBar.Children.Where <UIElement>(predicate).FirstOrDefault <UIElement>(); if (item != null) { int count = taskBar.Children.Count; taskBar.Children.Remove(item); double parentWidth = taskBar.ActualWidth - taskBar.Children.Count - 78; double itemWidth = parentWidth / taskBar.Children.Count; if (itemWidth < item.InitWidth) { foreach (FrameworkElement child in taskBar.Children) { child.Width = itemWidth; } } else if (itemWidth > item.InitWidth) { foreach (FrameworkElement child in taskBar.Children) { child.Width = ((TaskBarItem)child).InitWidth; } } } } ArrangeActiveWindow(); GC.Collect(); }
private static void taskBarItem_Clicked(object sender, EventArgs e) { TaskBarItem taskBarItem = (TaskBarItem)sender; Window window = (Window)desktop.Children.Where <UIElement>(delegate(UIElement i) { return((i is Window) && (((Window)i).Name == taskBarItem.Name.Substring(2))); }).FirstOrDefault <UIElement>(); if (window != null) { if (window.Visibility == Visibility.Collapsed) { if (!window.IsHideWindow) { window.Visibility = Visibility.Visible; GeneralTransform gentransform = taskBarItem.TransformToVisual(desktop); Point point = gentransform.Transform(new Point(0, 0)); Point to = new Point(Canvas.GetLeft(window), Canvas.GetTop(window)); Storyboard PrepareWindow = CommonAnimation.PrepareWindow (window, window.TimeOffset, point, window.TaskBarPoint, new Size(2, 2), window.HideWindowSize, 0, 1, true); PrepareWindow.Begin(); PrepareWindow.Completed += (ob, arg) => { window.IsHideWindow = true; }; } } else { if (window.IsHideWindow) { GeneralTransform gentransform = taskBarItem.TransformToVisual(desktop); Point point = gentransform.Transform(new Point(0, 0)); window.TaskBarPoint = new Point(Canvas.GetLeft(window), Canvas.GetTop(window)); window.HideWindowSize = new Size(window.Width, window.Height); Storyboard PrepareWindow = CommonAnimation.PrepareWindow (window, window.TimeOffset, window.TaskBarPoint, point, window.HideWindowSize, new Size(2, 2), 1, 0, true); PrepareWindow.Begin(); PrepareWindow.Completed += (o, arg) => { window.Visibility = Visibility.Collapsed; window.IsHideWindow = false; }; ArrangeActiveWindow(); } } window.Focus(); } }
/// <summary> /// 根据应用程序窗口信息添加对于的人物栏按钮 /// </summary> /// <param name="w"></param> private static void AddTaskBarItem(Window w) { if (taskBar != null) { double parentWidth = taskBar.ActualWidth; TaskBarItem item = new TaskBarItem(); item.Name = "tb" + w.Name; item.Caption = w.Caption; item.IocPath = w.IocPath; item.InitWidth = 86; item.Clicked += new EventHandler(WindowsManager.taskBarItem_Clicked); taskBar.Children.Add(item); #region 控制任务栏按钮的缩放 int itemcount = taskBar.Children.Count; if (itemcount > 1) { ((TaskBarItem)taskBar.Children[itemcount - 2]).InitWidth = ((TaskBarItem)taskBar.Children[itemcount - 2]).ActualWidth; } double countItemWidth = 0; foreach (FrameworkElement child in taskBar.Children) { countItemWidth += child.ActualWidth; } countItemWidth += item.InitWidth; if (countItemWidth >= parentWidth - (taskBar.Children.Count * 2)) { double itemWidth = (parentWidth - (taskBar.Children.Count)) / taskBar.Children.Count; foreach (FrameworkElement child in taskBar.Children) { child.Width = itemWidth; } } #endregion } }
/// <summary> /// 激活窗口 /// </summary> /// <param name="WindowName"></param> public static void ActiveWindow(string WindowName) { ///根据窗口名称获取窗口在任务栏按钮的对象以及窗口对象 TaskBarItem taskBarItem = (TaskBarItem)taskBar.Children.Where <UIElement>(delegate(UIElement i) { return((i is TaskBarItem) && (((TaskBarItem)i).Name == "tb" + WindowName)); }).FirstOrDefault <UIElement>(); Window window = (Window)desktop.Children.Where <UIElement>(delegate(UIElement i) { return((i is Window) && (((Window)i).Name == WindowName)); }).FirstOrDefault <UIElement>(); ///判断窗口是否为NULL if (window != null) { //如果窗口视图为不显示则将其从任务栏位置显示出来 if (window.Visibility == Visibility.Collapsed) { if (!window.IsHideWindow) { ///设置窗口显示,并使用动画将其呈现 window.Visibility = Visibility.Visible; GeneralTransform gentransform = taskBarItem.TransformToVisual(desktop); Point point = gentransform.Transform(new Point(0, 0)); Point to = new Point(Canvas.GetLeft(window), Canvas.GetTop(window)); Storyboard PrepareWindow = CommonAnimation.PrepareWindow (window, window.TimeOffset, point, window.TaskBarPoint, new Size(2, 2), window.HideWindowSize, 0, 1, true); PrepareWindow.Begin(); PrepareWindow.Completed += (ob, arg) => { window.IsHideWindow = true; }; } } else { Canvas.SetZIndex(window, Window.currentZIndex++); } window.Focus(); } }
private static void window_Minimized(object sender, EventArgs e) { Window window = (Window)sender; TaskBarItem item = (TaskBarItem)taskBar.Children.Where <UIElement>(delegate(UIElement i) { return((i is TaskBarItem) && (((TaskBarItem)i).Name == "tb" + window.Name)); }).FirstOrDefault <UIElement>(); if (window.IsHideWindow) { GeneralTransform gentransform = item.TransformToVisual(desktop); Point point = gentransform.Transform(new Point(0, 0)); window.TaskBarPoint = new Point(Canvas.GetLeft(window), Canvas.GetTop(window)); window.HideWindowSize = new Size(window.Width, window.Height); Storyboard PrepareWindow = CommonAnimation.PrepareWindow (window, window.TimeOffset, window.TaskBarPoint, point, window.HideWindowSize, new Size(2, 2), 1, 0, true); PrepareWindow.Begin(); PrepareWindow.Completed += (o, arg) => { window.Visibility = Visibility.Collapsed; window.IsHideWindow = false; }; ArrangeActiveWindow(); } }
public static void OnIocPathProperty(DependencyObject d, DependencyPropertyChangedEventArgs e) { TaskBarItem item = (TaskBarItem)d; item.iocImage.Source = new BitmapImage(new Uri((string)e.NewValue, UriKind.Relative)); }