/// <summary> /// 拖拽任务栏项 /// </summary> /// <param name="p_src"></param> /// <param name="e"></param> internal void DoSwap(TaskbarItem p_src, PointerRoutedEventArgs e) { Point pt = e.GetCurrentPoint(null).Position; TaskbarItem tgt = (from item in _taskbarPanel.Children.OfType <TaskbarItem>() where item.ContainPoint(pt) select item).FirstOrDefault(); if (tgt != null && tgt != p_src) { // 交换位置的最小移动控制 pt = e.GetCurrentPoint(tgt).Position; double delta = tgt.ActualWidth / 2; if ((pt.X < delta && pt.X > 20) || (pt.X > delta && pt.X < tgt.ActualWidth - 20)) { try { // 动画效果好 Items.ItemsChanged -= OnItemsChanged; int srcIndex = _taskbarPanel.Children.IndexOf(p_src); int tgtIndex = _taskbarPanel.Children.IndexOf(tgt); Items.RemoveAt(tgtIndex); _taskbarPanel.Children.RemoveAt(tgtIndex); Items.Insert(srcIndex, (Win)tgt.DataContext); _taskbarPanel.Children.Insert(srcIndex, tgt); } finally { Items.ItemsChanged += OnItemsChanged; } } } }
protected override void OnRightTapped(RightTappedRoutedEventArgs e) { e.Handled = true; _currentItem = this; ShowMenu(e.GetPosition(SysVisual.RootContent)); }