Exemple #1
0
        private void DragSource_PreviewMouseLeftButtonDown(object sender,
                                                           MouseButtonEventArgs e)
        {
            var fe = DynamicFormUtilities.GetItemContainer(sender as ItemsControl,
                                                           e.OriginalSource as
                                                           Visual) as FrameworkElement;

            if (fe != null && fe.DataContext is PropertyInformation &&
                (fe.DataContext as PropertyInformation
                ).HasBeenUsed)
            {
                e.Handled = true;
                return;
            }

            InitialMousePosition = e.GetPosition(TopWindow);
            SourceItemsControl   = (ItemsControl)sender;
            TopWindow            = DynamicFormUtilities.FindAncestor(typeof(Window),
                                                                     SourceItemsControl) as Window;
            SourceItemContainer = DynamicFormUtilities.GetItemContainer(
                SourceItemsControl, e.OriginalSource
                as Visual);

            if (SourceItemContainer != null)
            {
                DraggedData = SourceItemContainer.DataContext;
            }
        }
Exemple #2
0
        private void DecideDropTarget(DragEventArgs e)
        {
            logger.Trace("Entered DecideDropTarget()");

            var targetItemsControlCount = TargetItemsControl.Items.Count;
            var draggedItem             = e.Data.GetData(Format.Name);

            if (IsDropDataTypeAllowed(draggedItem))
            {
                if (targetItemsControlCount > 0)
                {
                    HasVerticalOrientation = DynamicFormUtilities.HasVerticalOrientation(
                        TargetItemsControl.
                        ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement);

                    TargetItemContainer = DynamicFormUtilities.GetItemContainer(
                        TargetItemsControl, e.
                        OriginalSource as Visual);

                    if (TargetItemContainer != null)
                    {
                        IsInFirstHalf = DynamicFormUtilities.IsInFirstHalf(TargetItemContainer,
                                                                           e.GetPosition(TargetItemContainer),
                                                                           HasVerticalOrientation);
                        InsertionIndex =
                            TargetItemsControl.ItemContainerGenerator.IndexFromContainer(
                                TargetItemContainer);

                        if (!IsInFirstHalf)
                        {
                            InsertionIndex++;
                        }
                    }
                    else
                    {
                        TargetItemContainer =
                            TargetItemsControl.ItemContainerGenerator.ContainerFromIndex(
                                targetItemsControlCount - 1) as FrameworkElement;
                        IsInFirstHalf  = false;
                        InsertionIndex = targetItemsControlCount;
                    }
                }
                else
                {
                    TargetItemContainer = null;
                    InsertionIndex      = 0;
                }
            }
            else
            {
                TargetItemContainer = null;
                InsertionIndex      = -1;
                e.Effects           = DragDropEffects.None;
            }
        }