//--------------------------------------------------------------------------------------------------------- /// <summary> /// Бросание модели над коллекцией моделей /// </summary> /// <param name="model">Модель</param> /// <param name="item">Коллекция</param> /// <param name="args">Аргументы события</param> /// <returns>Статус обработки события</returns> //--------------------------------------------------------------------------------------------------------- public Boolean DropModelOverCollectionModel(ICubeXModel model, TreeViewItem item, DragEventArgs args) { ICubeXCollectionModel collection_model = item.DataContext as ICubeXCollectionModel; // Если коллекция поддерживает данную модель if (collection_model != null && collection_model.IsSupportModel(model as ICubeXModelOwned)) { // Проверка на поддержку операции добавления ICubeXCollectionSupportAdd operation_add = item.DataContext as ICubeXCollectionSupportAdd; if (operation_add != null) { if (args.Effects == DragDropEffects.Move) { ICubeXModelOwned model_owned = model as ICubeXModelOwned; SetGroupProperties(model_owned, operation_add.IModels[0] as ICubeXModelOwned); operation_add.AddExistingModel(model_owned); } else { if (args.Effects == DragDropEffects.Copy) { ICubeXModelOwned model_owned = model.Clone() as ICubeXModelOwned; SetGroupProperties(model_owned, operation_add.IModels[0] as ICubeXModelOwned); operation_add.AddExistingModel(model_owned); } } } return(true); } return(false); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Событие постоянно возникает при перетаскивании данных над объектом-приемником /// </summary> /// <param name="sender">Источник события</param> /// <param name="args">Аргументы события</param> //--------------------------------------------------------------------------------------------------------- private void OnTreeView_DragOver(Object sender, DragEventArgs args) { if (args.Data.GetDataPresent(nameof(ICubeXModel))) { ICubeXModel model = args.Data.GetData(nameof(ICubeXModel)) as ICubeXModel; // Над этим элементом находится перетаскиваемый объект TreeViewItem over_item = ((DependencyObject)args.OriginalSource).FindVisualParent <TreeViewItem>(); if (over_item != null) { ICubeXCollectionModel collection_model = over_item.DataContext as ICubeXCollectionModel; if (collection_model != null && collection_model.IsSupportModel(model as ICubeXModelOwned)) { } else { ICubeXModelOwned model_owned = over_item.DataContext as ICubeXModelOwned; if (model_owned != null) { ICubeXCollectionModel model_owned_collection = model_owned.IOwner; if (model_owned_collection != null && model_owned_collection.IsSupportModel(model as ICubeXModelOwned)) { } else { args.Effects = DragDropEffects.None; } } else { args.Effects = DragDropEffects.None; } } } } }