예제 #1
0
        public static void AdornDropTarget(DropInfo dropInfo)
        {
            if (dropInfo == null) throw new ArgumentNullException("dropInfo");
            if (dropInfo.Type == DataSourceDropType.None)
                throw new ArgumentException("dropInfo.DropType may not be set to none");

            if (dropInfo.Type.HasFlag(DataSourceDropType.Group))
            {
                if (dropInfo.TargetGroup == null)
                    throw new ArgumentException("dropInfo.Group is set to null but the type is set to group");

                AddDropAdorner(dropInfo.TargetGroup.TreeViewItem);
            }
            else
            {
                RemoveDropAdorner();
            }

            if (dropInfo.Type.HasFlag(DataSourceDropType.ArrangeTop) ||
                dropInfo.Type.HasFlag(DataSourceDropType.ArrangeBottom))
            {
                AddArrangeAdorner(dropInfo.Target.TreeViewItem, dropInfo.Type);
            }
            else
            {
                RemoveArrangeAdorner();
            }
        }
예제 #2
0
        private bool IsValidDrop(DragEventArgs e, out DropInfo dropInfo)
        {
            dropInfo = null;
            IDataSourceViewModel viewModel = e.Data.GetData(typeof (SingleDataSourceViewModel)) as IDataSourceViewModel ??
                                             e.Data.GetData(typeof (MergedDataSourceViewModel)) as IDataSourceViewModel;
            var source = new TreeItem
                {
                    ViewModel = viewModel
                };
            if (source.ViewModel == null)
                return false;

            TreeItem dropTarget = GetDataSourceFromPosition(e.GetPosition(_partDataSources));
            if (dropTarget == null)
                return false;

            DataSourceDropType dropType = GetDropType(e, dropTarget, viewModel);
            var model = (MainWindowViewModel) DataContext;
            IDataSourceViewModel group;
            if (!model.CanBeDropped(source.ViewModel, dropTarget.ViewModel, dropType, out group))
                return false;

            dropInfo = new DropInfo
                {
                    Source = source,
                    Type = dropType,
                    Target = dropTarget,
                    TargetGroup = new TreeItem
                        {
                            ViewModel = group,
                            TreeViewItem = GetTreeViewItem(group)
                        }
                };
            return true;
        }