コード例 #1
0
        public static void IsDragSelectingEnabledPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ListView listView = o as ListView;

            bool isDragSelectionEnabled = DragSelectionHelper.GetIsDragSelectionEnabled(listView);

            // if DragSelection is enabled
            if (isDragSelectionEnabled)
            {
                // set the listbox's selection mode to multiple ( didn't work with extended )
                listView.SelectionMode = SelectionMode.Multiple;

                // set the static listbox property
                DragSelectionHelper.ListView = listView;

                // and subscribe to the required events to handle the drag selection and the attached properties
                listView.PreviewMouseLeftButtonDown  += new MouseButtonEventHandler(DragSelectionHelper.listBox_PreviewMouseLeftButtonDown);
                listView.PreviewMouseRightButtonDown += new MouseButtonEventHandler(listBox_PreviewMouseRightButtonDown);
                listView.MouseLeftButtonUp           += new MouseButtonEventHandler(DragSelectionHelper.listBox_MouseLeftButtonUp);
            }
            else // is selection is disabled
            {
                // set selection mode to the default
                listView.SelectionMode = SelectionMode.Single;

                // dereference the listbox
                DragSelectionHelper.ListView = null;

                // unsuscribe from the events
                listView.PreviewMouseLeftButtonDown  -= new MouseButtonEventHandler(DragSelectionHelper.listBox_PreviewMouseLeftButtonDown);
                listView.PreviewMouseRightButtonDown -= new MouseButtonEventHandler(DragSelectionHelper.listBox_PreviewMouseRightButtonDown);
                listView.MouseLeftButtonUp           -= new MouseButtonEventHandler(DragSelectionHelper.listBox_MouseLeftButtonUp);
            }
        }
コード例 #2
0
        public static void IsDragClickStartedPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            bool isDragClickStarted = DragSelectionHelper.GetIsDragClickStarted(DragSelectionHelper.ListView);

            // if click has been drag click has started, clear the current selected items and start drag selection operation again
            if (isDragClickStarted)
            {
                DragSelectionHelper.ListView.SelectedItems.Clear();
            }
        }
コード例 #3
0
        public static void IsDragSelectingPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ListViewItem item = o as ListViewItem;

            bool clickInitiated = DragSelectionHelper.GetIsDragClickStarted(DragSelectionHelper.ListView);

            // this is where the item.Parent was null, it was supposed to be the ListBox, I guess it's null because items are not
            // really ListBoxItems but are wells
            if (clickInitiated)
            {
                bool isDragSelecting = DragSelectionHelper.GetIsDragSelecting(item);

                if (isDragSelecting)
                {
                    // using the ListBox static reference because could not get to it through the item.Parent property
                    DragSelectionHelper.ListView.SelectedItems.Add(item);
                }
            }
        }
コード例 #4
0
 private static void listBox_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     // notify the helper class that the list box has terminated the drag click
     DragSelectionHelper.SetIsDragClickStarted(DragSelectionHelper.ListView, false);
 }
コード例 #5
0
 private static void listBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     // notify the helper class that the listbox has initiated the drag click
     DragSelectionHelper.SetIsDragClickStarted(DragSelectionHelper.ListView, true);
 }