Пример #1
0
        public void DragEnd(DragInfo info)
        {
            if (_dragStartIndex < 0)
            {
                return;
            }
            RadListBox rlb = info.Source as RadListBox;

            if (rlb != null)
            {
                TimeSwitchViewModel vm = rlb.DataContext as TimeSwitchViewModel;
                if (vm != null)
                {
                    vm.ToDropPlan(_dragStartIndex);
                }
                _dragStartIndex = -1;
            }
        }
Пример #2
0
        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();
                }
            }
        }
Пример #3
0
        public void Drop(DropInfo info)
        {
            RadListBox rlb = info.Source as RadListBox;

            if (rlb != null)
            {
                TimeSwitchViewModel source = rlb.DataContext as TimeSwitchViewModel;
                if (source != null && source.DragPlan != null && source.DragPlan != TimeSwitchViewModel.AddPlanStatic)
                {
                    var dragSource             = source.DragPlan;
                    TimeSwitchViewModel target = (info.Target as RadListBox)?.DataContext as TimeSwitchViewModel;
                    if (target != source)
                    {
                        return;
                    }
                    if (target != null)
                    {
                        var list = target.PlansSource.Source as ObservableCollection <LayoutPlanModel>;
                        source.ToDropPlan(info.InsertIndex);
                        GC.Collect();
                    }
                }
            }
        }