public void DragStart(DragInfo info) { if (info.SourceItem == null) { info.Cancelled = true; return; } RadListBox rlb = info.Source as RadListBox; if (rlb != null) { //设置拖拽窗口视觉效果。 IEnumerable <RadListBoxItem> items = rlb.FindVisualChildren <RadListBoxItem>(); foreach (RadListBoxItem item in items) { if (item.DataContext.Equals(rlb.SelectedItem)) { rlb.SetValue(DragDropVisual.VisualProperty, item); break; } } SearchNodeHistoryViewModel searchVM = rlb.DataContext as SearchNodeHistoryViewModel; if (searchVM == null || searchVM.SelectedVideo == null) {//如果没有选中项,或者选中项不是视频节点,取消拖拽。 info.Cancelled = true; } } }
public void DragStart(DragInfo info) { if (info.SourceItem == null || info.EventOriginalSource is TextBox) { info.Cancelled = true; return; } RadListBox rlb = info.Source as RadListBox; if (rlb != null) { //设置拖拽窗口视觉效果。 IEnumerable <RadListBoxItem> items = rlb.FindVisualChildren <RadListBoxItem>(); foreach (RadListBoxItem item in items) { if (item.DataContext.Equals(rlb.SelectedItem)) { ContentPresenter cp = item.FindVisualChild <ContentPresenter>(); if (cp != null) { rlb.SetValue(DragDropVisual.VisualProperty, cp); } else { rlb.SetValue(DragDropVisual.VisualProperty, item); } break; } } TimeSwitchViewModel vm = rlb.DataContext as TimeSwitchViewModel; //如果没有选中项,或者选中项不是有效节点,取消拖拽。 if (!(vm != null && vm.SelectedPlan != null && vm.SelectedPlan != TimeSwitchViewModel.AddPlanStatic)) { info.Cancelled = true; } else if (vm != null && vm.SelectedPlan != null) { var list = vm.PlansSource.Source as ObservableCollection <LayoutPlanModel>; _dragStartIndex = list.IndexOf(vm.SelectedPlan); vm.ToDragPlan(); } } }