Example #1
0
        /// <summary>
        /// Changes item's name.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        private void _ChangeName(DataGridItemEventArgs e)
        {
            // Get custom order property from event's data.
            CustomOrderProperty orderProperty = e.Item as CustomOrderProperty;

            Debug.Assert(orderProperty != null);

            // Check that item's name is null.
            if (!string.IsNullOrEmpty(orderProperty.Name))
            {
                return;
            }

            // Get new item's name.
            orderProperty.Name =
                DataObjectNamesConstructor.GetNewNameForCustomOrderProperty(_customOrderProperties, true);

            // Get current cell.
            Cell currentCell =
                _insertionRow.Cells[_customOrderPropertiesXceedGrid.CurrentContext.CurrentColumn];

            // Find TextBox inside the cell.
            TextBox textBox = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            // Select contents of found text box.
            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
        /// <summary>
        /// Changed selection in RadioButtons and reloads project
        /// </summary>
        /// <param name="e"></param>
        private void _ChangeSelectedProject(RoutedEventArgs e)
        {
            if (XceedGrid.SelectedIndex != -1)
            {
                Row row = XceedVisualTreeHelper.GetRowByEventArgs(e);

                Debug.Assert(row != null);

                // NOTE : when user clicks so fast on radio buttons sometimes row's content can't be updated in time.
                // In that case we should do nothing
                if (row.Cells[NAME_COLUMN_CAPTION].Content == null)
                {
                    return;
                }

                string checkedProjectName = row.Cells[NAME_COLUMN_CAPTION].Content.ToString();

                _LoadProject(checkedProjectName);
                try
                {
                    XceedGrid.EndEdit();
                }
                catch
                {
                    XceedGrid.CancelEdit();
                }
            }
        }
 /// <summary>
 /// React on left button down. Check click on buttons or start drag otherwise.
 /// </summary>
 /// <param name="sender">Ignored.</param>
 /// <param name="e">Event args.</param>
 private void _PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     // Check close button pressed.
     if (_IsElementPressed(CloseButton, e))
     {
         // Hide hint.
         Visibility = Visibility.Collapsed;
     }
     // Check tool button pressed.
     else if (_IsElementPressed(PushpinToolButton, e))
     {
         // Change tool state.
         _AddressByPointToolPressed();
     }
     // Check link click.
     else if (_IsElementPressed(ZoomedAddress, e))
     {
         // Zoom to candidates.
         MapExtentHelpers.ZoomToCandidates(_mapControl, _candidatesToZoom);
     }
     else
     {
         // Start drag if mouse was clicked on canvas.
         GeocodingHint geocodingHint = XceedVisualTreeHelper.FindParent <GeocodingHint>((DependencyObject)e.Source);
         if (geocodingHint != null || e.Source == this)
         {
             _isDown     = true;
             _startPoint = e.GetPosition(_canvas);
             _canvas.CaptureMouse();
             e.Handled = true;
         }
     }
 }
Example #4
0
        /// <summary>
        /// When mouse move in invalid cell - show corresponding popup.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _dataGridMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // Find cell on which mouse moved.
            Cell cell = XceedVisualTreeHelper.GetCellByEventArgs(e);

            // If cell has error, grid isnt in editing state and timer is running - show callout.
            if (cell != null && cell.HasValidationError && !_timer.IsEnabled &&
                !_dataGrid.IsBeingEdited &&
                !(_dataGrid.InsertionRow != null && _dataGrid.InsertionRow.IsBeingEdited))
            {
                _showCallout = true;

                // Detect current column and item. Show callout.
                IDataErrorInfo currentItem =
                    _dataGrid.GetItemFromContainer(cell) as IDataErrorInfo;

                var columns = _dataGrid.GetVisibleColumns();
                _column      = columns.FirstOrDefault(x => x.FieldName == cell.FieldName);
                _InvalidItem = currentItem;
                _SetPopupPosition();

                _showCallout = false;

                // When mouse leave current cell - callout must be hided.
                cell.MouseLeave += new System.Windows.Input.MouseEventHandler(_MouseLeaveCellWithInvalidProperty);
            }
        }
        private void DatePickerEx_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Tab && e.Key != System.Windows.Input.Key.Enter)
            {
                return;
            }

            // get current value of control's text (need to save changes)
            DateTime?editedDate = _StringToDateTime(this.Text);

            if (editedDate != null)
            {
                this.SelectedDate = editedDate;
            }

            if (e.Key == System.Windows.Input.Key.Enter)
            {
                DataGridControl parentControl = XceedVisualTreeHelper.GetGridByEditor(this);
                if (parentControl != null) // if parent grid is found - call "EndEdit" method. It commits new item or saves changes.
                {
                    try
                    {
                        parentControl.EndEdit();
                    }
                    catch
                    {
                        // NOTE : if current object is invalid and cannot be commited only stay focus in control
                        parentControl.Focus();
                    }
                }
            }
        }
        private void _PopupPanel_Closed(object sender, EventArgs e)
        {
            UIElement cell = XceedVisualTreeHelper.GetCellByEditor(this);

            if (cell != null)
            {
                Keyboard.Focus(cell);
            }
        }
Example #7
0
 /// <summary>
 /// Find ScrollViewer from cell and subscribe to it scroll changed event.
 /// </summary>
 /// <param name="cell">Cell.</param>
 private void _SubscribeOnScroller(Cell cell)
 {
     _scrollViewer = XceedVisualTreeHelper.FindScrollViewer(cell);
     if (_scrollViewer != null)
     {
         _scrollViewer.ScrollChanged += new System.Windows.Controls.
                                        ScrollChangedEventHandler(_ScrollViewerScrollChanged);
     }
 }
Example #8
0
        private void _PopupPanelClosed(object sender, EventArgs e)
        {
            // NOTE : set focus to parent cell for support arrow keys navigation
            UIElement cell = XceedVisualTreeHelper.GetCellByEditor(this);

            if (cell != null)
            {
                Keyboard.Focus(cell);
            }
        }
        /// <summary>
        /// Registers that drag and drop can potentially start.
        /// </summary>
        /// <param name="sender">Data grid.</param>
        /// <param name="e">Event args.</param>
        private void _DataGridControlPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Check that user clicked on a row.
            Row row = XceedVisualTreeHelper.GetRowByEventArgs(e);

            if (row != null && row is DataRow && !(row is InsertionRow)) // Don't start drag of insertion row.
            {
                // We must start dragging on mouse move.
                _mustStartDraggingOnMouseMove = true;
            }
        }
Example #10
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Sets focus to relative cell.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _ComboBox_DropDownClosed(object sender, EventArgs e)
        {
            UIElement cell = XceedVisualTreeHelper.GetCellByEditor(this);

            if (cell != null)
            {
                Keyboard.Focus(cell);
            }

            if (DropDownClosed != null)
            {
                DropDownClosed(this, null);
            }
        }
        /// <summary>
        /// Changes cursor during user drags over DataGridControl.
        /// </summary>
        /// <param name="sender">DataGridControl.</param>
        /// <param name="e">Event args.</param>
        private void _DragOverGrid(object sender, DragEventArgs e)
        {
            Row draggedOverRow = XceedVisualTreeHelper.GetRowByEventArgs(e);

            if (draggedOverRow is InsertionRow || draggedOverRow is ColumnManagerRow ||
                (!(e.OriginalSource is TableViewScrollViewer) && draggedOverRow == null))
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
            else
            {
                e.Effects = DragDropEffects.Move;
            }
        }
        /// <summary>
        /// Drops orders to grid.
        /// </summary>
        /// <param name="sender">DataGridControl.</param>
        /// <param name="e">Event args.</param>
        private void _OrdersGridDrop(object sender, DragEventArgs e)
        {
            // Get row where object was dropped.
            Row parentRow = XceedVisualTreeHelper.GetRowByEventArgs(e);

            object targetData = OrdersGrid;

            if (parentRow != null)
            {
                targetData = _GetTargetData(parentRow); // Get data from dropped object.
            }
            // Do necessary actions (move or reassign routes etc.).
            DragAndDropHelper dragAndDropHelper = new DragAndDropHelper();

            dragAndDropHelper.Drop(targetData, e.Data);
        }
 /// <summary>
 /// React on mouse up. Try to geocode order.
 /// </summary>
 /// <param name="sender">Ignored.</param>
 /// <param name="e">Ignored.</param>
 private void _DataGridControlPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     // Do not start geocoding in case of shift or control used or selected more than one order.
     if (_schedulePage.SelectedItems.Count == 1 && (Keyboard.Modifiers & ModifierKeys.Shift) == 0 &&
         (Keyboard.Modifiers & ModifierKeys.Control) == 0)
     {
         Order order = _schedulePage.SelectedItems[0] as Order;
         Row   row   = XceedVisualTreeHelper.GetRowByEventArgs(e);
         if (order != null && !order.IsGeocoded && !_schedulePage.GeocodablePage.IsGeocodingInProcess &&
             !_schedulePage.IsEditingInProgress && row != null)
         {
             // Geocode order.
             _schedulePage.GeocodablePage.StartGeocoding(order);
         }
     }
 }
        /// <summary>
        /// Finds TableViewScrollViewer in visual tree and adds handler to it's "ScrollChanged" event.
        /// Also adds handler to "Unloaded" event of cell editor to remove handlers when it will be unloaded.
        /// </summary>
        private void _SubscribeEvents()
        {
            Debug.Assert(_cellEditor != null);
            Debug.Assert(_popup != null);

            TableViewScrollViewer scrollViewer = XceedVisualTreeHelper.FindScrollViewer(_cellEditor);

            if (scrollViewer != null)
            {
                _scrollViewer = scrollViewer;
                _scrollViewer.ScrollChanged += new ScrollChangedEventHandler(_ScrollViewerScrollChanged);
            }
            else
            {
                // Do nothing, because scroll viewer wasn't found.
            }
        }
        /// <summary>
        /// Do convertion. Set background to textbox if empty value.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType">Ignored.</param>
        /// <param name="parameter">Ignored.</param>
        /// <param name="culture">Ignored.</param>
        /// <returns>Null, if background was set. Cell value otherwise.</returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            TextBlock textBlock = value[1] as TextBlock;

            if (textBlock == null)
            {
                return(null);
            }

            // Get datagridcontrol cell.
            DataCell cell = XceedVisualTreeHelper.FindParent <DataCell>(textBlock);

            if (cell == null)
            {
                return(null);
            }

            // Get location.
            Location location = cell.DataContext as Location;

            // Get background brush.
            Brush backgroundBrush = _GetBackgroundBrushForCell(cell);

            // Brush need to be set only if address fields is empty.
            if (GeocodeHelpers.IsActiveAddressFieldsEmpty(location))
            {
                // Workaround for .NET 4.0: Do not not change value if not needed.
                if (textBlock.Background != backgroundBrush)
                {
                    textBlock.Background = backgroundBrush;
                }
            }
            else if (textBlock.Background != null)
            {
                textBlock.Background = null;
            }
            else
            {
                // Do nothing.
            }

            return(value[0]);
        }
        /// <summary>
        /// If it is polyline barrier then hide combobox and show textblock.
        /// </summary>
        private void _InitVisibility()
        {
            // Get Barrier.Geometry type.
            Cell    cell    = XceedVisualTreeHelper.GetCellByEditor(this);
            Row     row     = XceedVisualTreeHelper.FindParent <Row>(cell);
            Barrier barrier = row.DataContext as Barrier;

            // If barrier is polyline or have no geometry hide edit control.
            if (barrier.Geometry == null || barrier.Geometry is ESRI.ArcLogistics.Geometry.Polyline)
            {
                _border.Visibility    = System.Windows.Visibility.Hidden;
                _popupPanel.Child     = null;
                _textBlock.Visibility = System.Windows.Visibility.Visible;
                if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polyline)
                {
                    _textBlock.Text = (string)App.Current.FindResource("BlockTravelString");
                }
            }
        }
        /// <summary>
        /// Change the name of the project.
        /// </summary>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _ChangeNewProjectName(DataGridItemEventArgs e)
        {
            // Check that item's name is null.
            if (!string.IsNullOrEmpty((e.Item as ProjectDataWrapper).Name))
            {
                return;
            }

            // Get new project name.
            (e.Item as ProjectDataWrapper).Name = DataObjectNamesConstructor.GetNewNameForProject();

            // Find TextBox inside the cell and select new name.
            Cell    currentCell = _InsertionRow.Cells[XceedGrid.CurrentContext.CurrentColumn];
            TextBox textBox     = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
Example #18
0
        /// <summary>
        /// React on click.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            // Get order which will be selected later by parent row.
            Row row = XceedVisualTreeHelper.GetRowByEventArgs(e);

            if (row != null)
            {
                Order order = row.DataContext as Order;

                if (order != null && order.PlannedDate.HasValue)
                {
                    List <Order> orderList = new List <Order>();
                    orderList.Add(order);
                    _optimizeAndEditPage.Select(orderList); // exception
                }

                // We must start dragging on mouse move.
                _mustStartDraggingOnMouseMove = true;
            }
        }
Example #19
0
        /// <summary>
        /// Change item's name.
        /// </summary>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _ChangeName(Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Check that item's name is null.
            if (!string.IsNullOrEmpty((e.Item as Route).Name))
            {
                return;
            }

            // Get new item's name.
            (e.Item as Route).Name = DataObjectNamesConstructor.GetNameForNewDataObject(
                App.Current.Project.DefaultRoutes, e.Item as Route, true);

            // Find TextBox inside the cell and select new name.
            Cell    currentCell = _InsertionRow.Cells[XceedGrid.CurrentContext.CurrentColumn];
            TextBox textBox     = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
        /// <summary>
        /// Change item's name.
        /// </summary>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _ChangeName(Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Check that item's name is null.
            if (!string.IsNullOrEmpty((e.Item as Order).Name))
            {
                return;
            }

            (e.Item as Order).Name = DataObjectNamesConstructor.GetNameForNewDataObject(
                (IDataObjectCollection <Order>)_collectionSource.Source, e.Item as Order, false);

            Cell currentCell = _ordersInsertionRow.Cells[OrdersGrid.CurrentContext.CurrentColumn];

            // Find TextBox inside the cell and select new name.
            TextBox textBox = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
        /// <summary>
        /// React on dependency property changing.
        /// </summary>
        private void _OnValueChanged()
        {
            if (_barrier != null)
            {
                _barrier.PropertyChanged -= new PropertyChangedEventHandler(_BarrierPropertyChanged);
            }

            Cell cell = XceedVisualTreeHelper.GetCellByEditor(this);
            Row  row  = XceedVisualTreeHelper.FindParent <Row>(cell);

            _barrier = row.DataContext as Barrier;

            if (_barrierEditor != null)
            {
                _barrierEditor.Barrier = _barrier;
            }

            if (_barrier != null)
            {
                _barrier.PropertyChanged += new PropertyChangedEventHandler(_BarrierPropertyChanged);
            }
        }
        /// <summary>
        /// Gets current background brush for cell.
        /// </summary>
        /// <param name="cell">Cell.</param>
        /// <returns>Current background brush.</returns>
        private Brush _GetBackgroundBrushForCell(DataCell cell)
        {
            Debug.Assert(cell != null);

            // Get layoutroot to get access to background brushes.
            Grid layoutRootGrid = _GetLayoutRootGrid(cell);

            // Get datagridcontrol to check is location first in collection.
            DataGridControl dataGridControl =
                XceedVisualTreeHelper.FindParent <DataGridControl>(cell);

            int indexOfItem = -1;

            try
            {
                // Workaround: Sometimes grid throws exception.
                indexOfItem = dataGridControl.Items.IndexOf(cell.DataContext);
            }
            catch { }

            Brush backgroundBrush;

            if (indexOfItem == 0)
            {
                // Use "Add location" string for first item.
                backgroundBrush =
                    (Brush)layoutRootGrid.Resources[AddLocationBrushResourceName];
            }
            else
            {
                // Use "Add another location" string for other items.
                backgroundBrush =
                    (Brush)layoutRootGrid.Resources[AddAnotherLocationBrushResourceName];
            }

            return(backgroundBrush);
        }