예제 #1
0
        static void DragSource_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // If the sender is allows multiple selections, select the DragInfo source item
            ItemsControl itemsControl = sender as ItemsControl;

            if (m_DragInfo != null &&
                m_DragInfo.VisualSourceItem != null &&
                itemsControl != null &&
                itemsControl.CanSelectMultipleItems() &&
                Keyboard.Modifiers != ModifierKeys.Shift &&
                Keyboard.Modifiers != ModifierKeys.Control &&
                Keyboard.Modifiers != (ModifierKeys.Control | ModifierKeys.Shift))
            {
                IEnumerable <object> selectedItems = itemsControl.GetSelectedItems().Cast <object>();

                if (selectedItems.Count() > 1 && selectedItems.Contains(m_DragInfo.SourceItem))
                {
                    itemsControl.SetSelectedItem(m_DragInfo.SourceItem);
                }
            }

            if (m_DragInfo != null)
            {
                m_DragInfo = null;
            }
        }
예제 #2
0
        static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Ignore the click if the user has clicked on a scrollbar.
            if (HitTestScrollBar(sender, e) || e.ClickCount > 1)
            {
                m_DragInfo = null;
                return;
            }

            m_DragInfo = new DragInfo(sender, e);

            // If the sender is a list box that allows multiple selections, ensure that clicking on an
            // already selected item does not change the selection, otherwise dragging multiple items
            // is made impossible.
            ItemsControl itemsControl = sender as ItemsControl;

            if (m_DragInfo.VisualSourceItem != null && itemsControl != null && itemsControl.CanSelectMultipleItems())
            {
                IEnumerable selectedItems = itemsControl.GetSelectedItems();

                if (selectedItems.Cast <object>().Contains(m_DragInfo.SourceItem))
                {
                    // TODO: Re-raise the supressed event if the user didn't initiate a drag.
                    e.Handled = true;
                }
            }
        }
예제 #3
0
        static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Ignore the click if the user has clicked on a scrollbar.
            if (HitTestScrollBar(sender, e))
            {
                m_DragInfo = null;
                return;
            }

            m_DragInfo = new DragInfo(sender, e);

            // If the sender is a list box that allows multiple selections, ensure that clicking on an
            // already selected item does not change the selection, otherwise dragging multiple items
            // is made impossible.
            ItemsControl itemsControl = sender as ItemsControl;


            // ignore the event if we reraised it to assure correct behavior
            if (ignoreEventOnce)
            {
                if (itemsControl is Selector && sourceItemTemp != null)
                {
                    ((Selector)itemsControl).SelectedItem = null;
                }
                ignoreEventOnce = false;
                return;
            }

            if (m_DragInfo.VisualSourceItem != null && itemsControl != null && itemsControl.CanSelectMultipleItems())
            {
                IEnumerable selectedItems = itemsControl.GetSelectedItems();

                if (selectedItems.Cast <object>().Contains(m_DragInfo.SourceItem))
                {
                    if (e.ClickCount == 1)
                    {
                        if (itemsControl is Selector && Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control)
                        {
                            sourceItemTemp = m_DragInfo.SourceItem;
                            argsSaved      = e;
                            e.Handled      = true;
                        }
                    }
                }
            }
        }