Пример #1
0
        public void Drop(IDropInfo dropInfo)
        {
            LauncherCommandInfoViewModel SourceCommandItem       = dropInfo.Data as LauncherCommandInfoViewModel;
            LauncherCommandInfoViewModel TargetCommandItem       = dropInfo.TargetItem as LauncherCommandInfoViewModel;
            MenuTreeNodeViewModel        SourceMenuItem          = dropInfo.Data as MenuTreeNodeViewModel;
            MenuTreeNodeViewModel        TargetMenuItem          = dropInfo.TargetItem as MenuTreeNodeViewModel;
            ObservableCollection <MenuTreeNodeViewModel> Targets = dropInfo.TargetCollection as ObservableCollection <MenuTreeNodeViewModel>;
            List <object> DataList = dropInfo.Data as List <object>;
            List <LauncherCommandInfoViewModel> SourceCommandItems = null;
            List <MenuTreeNodeViewModel>        SourceMenuItems    = null;

            if (DataList != null && DataList.Count > 0)
            {
                if (DataList[0] is LauncherCommandInfoViewModel)
                {
                    SourceCommandItems = new List <LauncherCommandInfoViewModel>(DataList.Select(x => (LauncherCommandInfoViewModel)x));
                }
                if (DataList[0] is MenuTreeNodeViewModel)
                {
                    SourceMenuItems = new List <MenuTreeNodeViewModel>(DataList.Select(x => (MenuTreeNodeViewModel)x));
                }
            }
            else
            {
                if (SourceCommandItem != null)
                {
                    SourceCommandItems = new List <LauncherCommandInfoViewModel>()
                    {
                        SourceCommandItem
                    };
                }
                if (SourceMenuItem != null)
                {
                    SourceMenuItems = new List <MenuTreeNodeViewModel>();
                    if (SelectedMenuNodes.Count > 1)
                    {
                        SourceMenuItems.AddRange(SelectedMenuNodes);
                    }
                    else
                    {
                        SourceMenuItems.Add(SourceMenuItem);
                    }
                }
            }
            if (Targets != null)
            {
                if (SourceCommandItems != null)
                {
                    DropCommandItemsToMenuTree(dropInfo, SourceCommandItems, TargetMenuItem, Targets);
                }
                if (SourceMenuItems != null)
                {
                    DropMenuItemsToMenuTree(dropInfo, SourceMenuItems, TargetMenuItem, Targets);
                }
                SelectedMenuNodes.Clear();
            }
        }
Пример #2
0
        public void DragOver(IDropInfo dropInfo)
        {
            LauncherCommandInfoViewModel SourceCommandItem       = dropInfo.Data as LauncherCommandInfoViewModel;
            LauncherCommandInfoViewModel TargetCommandItem       = dropInfo.TargetItem as LauncherCommandInfoViewModel;
            MenuTreeNodeViewModel        SourceMenuItem          = dropInfo.Data as MenuTreeNodeViewModel;
            MenuTreeNodeViewModel        TargetMenuItem          = dropInfo.TargetItem as MenuTreeNodeViewModel;
            ObservableCollection <MenuTreeNodeViewModel> Targets = dropInfo.TargetCollection as ObservableCollection <MenuTreeNodeViewModel>;
            List <object> DataList = dropInfo.Data as List <object>;
            List <LauncherCommandInfoViewModel> SourceCommandItems = null;
            List <MenuTreeNodeViewModel>        SourceMenuItems    = null;

            if (DataList != null && DataList.Count > 0)
            {
                if (DataList[0] is LauncherCommandInfoViewModel)
                {
                    SourceCommandItems = new List <LauncherCommandInfoViewModel>(DataList.Select(x => (LauncherCommandInfoViewModel)x));
                }
                else if (DataList[0] is MenuTreeNodeViewModel)
                {
                    SourceMenuItems = new List <MenuTreeNodeViewModel>(DataList.Select(x => (MenuTreeNodeViewModel)x));
                }
            }
            if (Targets != null)
            {
                if (SourceCommandItem != null || SourceCommandItems != null)
                {
                    dropInfo.Effects = DragDropEffects.Copy;
                }
                else if (SourceMenuItem != null || SourceMenuItems != null)
                {
                    dropInfo.Effects = DragDropEffects.Move;
                }
                if (dropInfo.InsertPosition == RelativeInsertPosition.None || dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter))
                {
                    dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
                    if (TargetMenuItem != null && TargetMenuItem.HasExecutableNode)
                    {
                        dropInfo.DropTargetAdorner = null;
                        dropInfo.Effects           = DragDropEffects.None;
                    }
                }
                else if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem) || dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.AfterTargetItem))
                {
                    dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
                }
            }
        }