Ejemplo n.º 1
0
        /// <summary>
        /// Adds a row at the specified index within the grid.
        /// </summary>
        /// <param name="index">Index to insert the row at.</param>
        /// <param name="model">The model to bind to the new row.</param>
        /// <param name="bindingMode">How to bind the model to the new row.</param>
        /// <returns>The newly created row.</returns>
        public GridRowViewModel InsertRow(int index, ModelBase model, ModelBindingMode bindingMode = ModelBindingMode.Committed)
        {
            var row = new GridRowViewModel(model, Columns, bindingMode);

            Rows.Insert(index, row);
            return(row);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the <see cref="GridRowViewModel"/> for the focused row.
        /// </summary>
        public GridRowViewModel GetFocusedRow()
        {
            GridRowViewModel row = null;

            var service = ServiceRepository.Instance.FindService <IBackgroundWorkerService>();

            service.InvokeOnUiThread(() =>
            {
                DependencyObject obj = Keyboard.FocusedElement as DependencyObject;
                while (obj != null)
                {
                    var element = obj as FrameworkElement;
                    if (element != null)
                    {
                        row = element.DataContext as GridRowViewModel;
                        if (row != null)
                        {
                            break;
                        }
                    }

                    obj = VisualTreeHelper.GetParent(obj);
                }
            });

            if (row != null && Rows.Contains(row))
            {
                return(row);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a row to the end of the grid.
        /// </summary>
        /// <param name="model">The model to bind to the new row.</param>
        /// <param name="bindingMode">How to bind the model to the new row.</param>
        /// <returns>The newly created row.</returns>
        public GridRowViewModel AddRow(ModelBase model, ModelBindingMode bindingMode = ModelBindingMode.Committed)
        {
            var row = new GridRowViewModel(model, Columns, bindingMode);

            Rows.Add(row);
            return(row);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the FieldViewModel responsible for rendering this column and binds it to the provided row.
        /// </summary>
        protected override FieldViewModelBase CreateFieldViewModel(GridRowViewModel row)
        {
            var viewModel = new ReadOnlyTextFieldViewModel(Header);

            viewModel.IsRightAligned = IsRightAligned;
            viewModel.SetBinding(ReadOnlyTextFieldViewModel.TextProperty, new ModelBinding(row, SourceProperty, ModelBindingMode.OneWay, _converter));
            return(viewModel);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the FieldViewModel responsible for rendering this column and binds it to the provided row.
        /// </summary>
        protected override FieldViewModelBase CreateFieldViewModel(GridRowViewModel row)
        {
            if (IsReadOnly)
            {
                var textViewModel = new ReadOnlyTextFieldViewModel(Header);
                textViewModel.IsRightAligned = true;
                textViewModel.SetBinding(ReadOnlyTextFieldViewModel.TextProperty, new ModelBinding(row, SourceProperty, ModelBindingMode.OneWay, _integerConverter));
                return(textViewModel);
            }

            var viewModel = new IntegerFieldViewModel(Header, _metadata);

            viewModel.BindValue(row, SourceProperty, ModelBindingMode.TwoWay);
            return(viewModel);
        }
Ejemplo n.º 6
0
        public GridRowCommandsViewModel(GridView view, GridRowViewModel row)
        {
            _view = view;
            _row  = row;

            RemoveCommand = new DelegateCommand(Remove);

            if (view.CanReorder)
            {
                MoveUpCommand   = new DelegateCommand(MoveUp);
                MoveDownCommand = new DelegateCommand(MoveDown);

                UpdateMoveCommands();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the FieldViewModel responsible for rendering this column and binds it to the provided row.
        /// </summary>
        protected override FieldViewModelBase CreateFieldViewModel(GridRowViewModel row)
        {
            if (IsReadOnly)
            {
                var textViewModel = new ReadOnlyTextFieldViewModel(Header);
                textViewModel.SetBinding(ReadOnlyTextFieldViewModel.TextProperty,
                                         new ModelBinding(row, SourceProperty, ModelBindingMode.OneWay, new DelegateConverter(id => _lookupLabelFunction((int)id), null)));
                return(textViewModel);
            }

            var viewModel = new AutoCompleteFieldViewModel(Header, _metadata, _searchFunction, _lookupLabelFunction);

            viewModel.IsDisplayTextDifferentFromSearchText = IsDisplayTextDifferentFromSearchText;

            // bind the property through to the data model
            row.SetBinding(_stringProperty, new ModelBinding(row.Model, _stringProperty));

            // bind text first so selection binding will cause it to be updated
            viewModel.SetBinding(AutoCompleteFieldViewModel.TextProperty, new ModelBinding(row, _stringProperty, ModelBindingMode.TwoWay));
            viewModel.BindSelection(row, SourceProperty, ModelBindingMode.TwoWay);

            return(viewModel);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates the FieldViewModel responsible for rendering this column and binds it to the provided row.
        /// </summary>
        protected override FieldViewModelBase CreateFieldViewModel(GridRowViewModel row)
        {
            if (IsReadOnly)
            {
                var textViewModel = new ReadOnlyTextFieldViewModel(Header);
                textViewModel.IsRightAligned = true;
                textViewModel.SetBinding(ReadOnlyTextFieldViewModel.TextProperty, new ModelBinding(row, SourceProperty, ModelBindingMode.OneWay, _dateConverter));
                return(textViewModel);
            }

            var viewModel = new DateFieldViewModel(Header, _metadata);

            if (SourceProperty.PropertyType == typeof(Date))
            {
                viewModel.BindDate(row, SourceProperty, ModelBindingMode.TwoWay);
            }
            else
            {
                viewModel.SetBinding(DateFieldViewModel.DateTimeProperty, new ModelBinding(row, SourceProperty, ModelBindingMode.TwoWay));
            }

            return(viewModel);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates the FieldViewModel responsible for rendering this column and binds it to the provided row.
 /// </summary>
 protected abstract FieldViewModelBase CreateFieldViewModel(GridRowViewModel row);
Ejemplo n.º 10
0
 internal FieldViewModelBase CreateFieldViewModelInternal(GridRowViewModel row)
 {
     return(CreateFieldViewModel(row));
 }