Beispiel #1
0
        public static FrameworkElement GetItemContainer(ItemsControl ItemsControl,
                                                        Visual BottomMostVisual)
        {
            FrameworkElement itemContainer = null;

            if (ItemsControl != null && BottomMostVisual != null && ItemsControl.Items.Count >= 1)
            {
                var firstContainer = ItemsControl.ItemContainerGenerator.ContainerFromIndex(0);

                if (firstContainer == null)
                {
                    return(itemContainer);                              // retyrn null;
                }

                itemContainer = DynamicFormUtilities.FindAncestor(firstContainer.GetType(),
                                                                  BottomMostVisual);

                if (itemContainer == null || itemContainer.DataContext == null)
                {
                    return(itemContainer);
                }

                var itemContainerVerify = ItemsControl.ItemContainerGenerator.ContainerFromItem(itemContainer.
                                                                                                DataContext) as FrameworkElement;

                if (itemContainer != itemContainerVerify)
                {
                    return(null);
                }
            }

            return(itemContainer);
        }
Beispiel #2
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;
            }
        }