private int _delayTime = 300; //延时时间。 public void DragOver(DropInfo info) { _mouseOn = true; if (info.KeyStates.HasFlag(DragDropKeyStates.ControlKey)) { info.Effects = DragDropEffects.Copy; } else { info.Effects = DragDropEffects.Move; } if (!_accepted) { VideoPanelItem vpi = info.Target as VideoPanelItem; VideoPanelItem srcVpi = info.Source as VideoPanelItem; //延时拖动接收。 if (Environment.TickCount - _startTick < _delayTime) { return; } string videoId = info.Data as string; if (videoId == null && info.DataType.ToUpper().EndsWith(".STRING")) { videoId = info.GetDataFromJson <string>(); } if (videoId == null) { info.Effects = DragDropEffects.None; return; } if (vpi != null && videoId != null && !vpi.Equals(srcVpi)) { _videoMode = vpi.ViewModel.ControlViewModel; DropAdorner = CreateAdorner(vpi); DropAdorner.VisualCover.Visibility = Visibility.Hidden; // Point toPnt = new Point(0, 0); double scaleX = 1; double scaleY = 1; if (srcVpi != null && IsBrothers(srcVpi, vpi)) { //隐藏源的视频。 if (vpi.VideoControl != null && vpi.ViewModel.ControlViewModel.IsVisible) { _videoMode.Opacity = 0; DropAdorner.VisualCover.Visibility = Visibility.Visible; toPnt = vpi.PointFromScreen(srcVpi.PointToScreen(new Point(0, 0))); scaleX = srcVpi.ActualWidth / vpi.ActualWidth; scaleY = srcVpi.ActualHeight / vpi.ActualHeight; } } //启动动画。 Storyboard sb = CreateStoryboard(toPnt, scaleX, scaleY, 1); sb.Begin(DropAdorner, true); _accepted = true; } } }
public void Drop(DropInfo info) { _mouseOn = false; _accepted = false; ResetAdorner(); if (_videoMode != null) { _videoMode.Opacity = 1; _videoMode = null; } string videoId = info.Data as string; if (videoId == null) { videoId = info.GetDataFromJson <string>(); } if (videoId != null) { VideoPanelItem vpi = info.Target as VideoPanelItem; if (vpi != null) { VideoPanelItem srcVpi = info.Source as VideoPanelItem; if (srcVpi != null && !srcVpi.Equals(vpi) && !info.KeyStates.HasFlag(DragDropKeyStates.ControlKey)) { //没有交换则直接设置ID。 if (!Exchange(srcVpi, vpi)) { vpi.PlayVideo(videoId); info.Effects = DragDropEffects.Copy; } else { info.Effects = DragDropEffects.Move; } } else { vpi.PlayVideo(videoId); info.Effects = DragDropEffects.Move; } } } }
private void Panel_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (ViewModel.OnSwitching && !ViewModel.SwitchPaused) { ViewModel.SwitchPaused = true; e.Handled = true; return; } VideoPanelItem item = sender as VideoPanelItem; foreach (VideoPanelItem vpi in gridMain.Children) { if (!item.Equals(vpi)) { vpi.ViewModel.ControlViewModel.IsControlPanelVisible = false; vpi.ViewModel.SearchedResultModel.IsVisible = false; vpi.ViewModel.PlusSignModel.IsVisible = true; } } }