コード例 #1
0
        private void OnExpanderDrop(object sender, DragEventArgs e)
        {
            StopViewModel stopVM = DataGridViewModel as StopViewModel;

            if (stopVM == null)
            {
                return;
            }
            if (_dragRowIndex < 0)
            {
                return;
            }
            //Schema.Item dragStop = e.Data.GetData(typeof(Schema.Item)) as Schema.Item;
            AddInsShare.Schema.Item dragStop = dgStops.Items[_dragRowIndex] as AddInsShare.Schema.Item;
            if (dragStop == null)
            {
                return;
            }

            // dropped on a Group?
            String routeName = GetDroppedOnGroupRouteName(e);

            if (routeName != null)
            {
                Log.Trace("Dropped item " + _dragRowIndex + " on group " + routeName);
                stopVM.CalculateRoute(dragStop, null, routeName, true, Window.GetWindow(this));
                return;
            }

            // dropped on an Item?
            int dropIndex = this.GetDataGridItemCurrentRowIndex(e.GetPosition);

            if (dropIndex < 0)
            {
                return;
            }
            if (dropIndex == _dragRowIndex)
            {
                return;
            }
            Log.Trace("Dropped item " + _dragRowIndex + " on item " + dropIndex);

            AddInsShare.Schema.Item dropStop = dgStops.Items[dropIndex] as AddInsShare.Schema.Item;
            if (dropStop == null)
            {
                return;
            }

            // Temp workaround - use the ALT key to drop onto the group (optimize == true)
            bool bOptimize = (e.KeyStates == DragDropKeyStates.AltKey);

            stopVM.CalculateRoute(dragStop, dropStop, null, bOptimize, Window.GetWindow(this));
        }
コード例 #2
0
        private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            StopViewModel stopVM = DataGridViewModel as StopViewModel;

            if (stopVM == null)
            {
                return;
            }

            bool bInEditMode = stopVM.InEditMode;

            // Adjust the Expander Context Menu on mouse right click
            if (e.RightButton == MouseButtonState.Pressed)
            {
                ContextMenu expanderContextMenu = (ContextMenu)FindResource("dgExpanderMenu");
                if (expanderContextMenu != null && expanderContextMenu.Items != null)
                {
                    foreach (var item in expanderContextMenu.Items)
                    {
                        MenuItem menuItem = item as MenuItem;
                        if (menuItem == null || menuItem.Header == null || menuItem.Header.ToString() == null)
                        {
                            continue;
                        }

                        if (menuItem.Header.ToString().Equals("Paste"))
                        {
                            if (bInEditMode && stopVM.CutStop != null)
                            {
                                menuItem.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                menuItem.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                }
                return;
            }

            // Support Drag & Drop
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (!bInEditMode)
                {
                    e.Handled = false;
                    return;
                }

                _dragRowIndex = GetDataGridItemCurrentRowIndex(e.GetPosition);
                if (_dragRowIndex < 0)
                {
                    return;
                }

                Log.Trace("Dragging item " + _dragRowIndex + " ...");

                AddInsShare.Schema.Item selectedStop = dgStops.Items[_dragRowIndex] as AddInsShare.Schema.Item;
                if (selectedStop == null)
                {
                    return;
                }

                if (DragDrop.DoDragDrop(dgStops, selectedStop, DragDropEffects.Move) != DragDropEffects.None)
                {
                    // now This Item will be dropped at a new location and so the new Selected Item
                    dgStops.SelectedItem = selectedStop;
                }
            }
        }