Exemplo n.º 1
0
        /// <summary>
        /// Gets the data context for the specified cell.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <returns>The context object.</returns>
        public object GetDataContext(DataGrid owner, CellRef cell)
        {
            var pd   = owner.GetPropertyDefinition(cell);
            var item = this.GetItem(owner, cell);

            return(pd.PropertyName != null ? item : owner.ItemsSource);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the value in the specified cell.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <returns>The value</returns>
        public virtual object GetCellValue(DataGrid owner, CellRef cell)
        {
            if (cell.Column < 0 || cell.Column >= owner.Columns || cell.Row < 0 || cell.Row >= owner.Rows)
            {
                return(null);
            }

            var item = this.GetItem(owner, cell);

            if (item != null)
            {
                var pd = owner.GetPropertyDefinition(cell);
                if (pd != null)
                {
                    var descriptor = this.GetPropertyDescriptor(pd);
                    if (descriptor != null)
                    {
                        return(descriptor.GetValue(item));
                    }

                    return(item);
                }
            }

            return(null);
        }
 /// <summary>
 /// Creates the cell definition for the specified cell.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="cell">The cell.</param>
 /// <returns>
 /// The cell definition
 /// </returns>
 public virtual CellDefinition CreateCellDefinition(
     DataGrid owner,
     CellRef cell)
 {
     var pd = owner.GetPropertyDefinition(cell);
     var item = owner.Operator.GetItem(owner, cell);
     var cd = this.CreateCellDefinitionOverride(owner, cell, pd, item);
     this.ApplyProperties(cd, owner, cell, pd, item);
     return cd;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the binding path for the specified cell.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <returns>
        /// The binding path
        /// </returns>
        public override string GetBindingPath(DataGrid owner, CellRef cell)
        {
            var pd = owner.GetPropertyDefinition(cell);

            if (pd?.PropertyName != null)
            {
                return(pd.PropertyName);
            }

            var index = this.GetItemIndex(owner, cell);

            return($"[{index}]");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Tries to set cell value in the specified cell.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="cell">The cell.</param>
        /// <param name="value">The value.</param>
        /// <returns><c>true</c> if the cell value was set.</returns>
        public virtual bool TrySetCellValue(DataGrid owner, CellRef cell, object value)
        {
            if (owner.ItemsSource != null)
            {
                var current = this.GetItem(owner, cell);

                var pd = owner.GetPropertyDefinition(cell);
                if (pd == null)
                {
                    return(false);
                }

                if (current == null || pd.IsReadOnly)
                {
                    return(false);
                }

                object convertedValue;
                var    targetType = this.GetPropertyType(pd, cell, current);
                if (!TryConvert(value, targetType, out convertedValue))
                {
                    return(false);
                }

                var descriptor = this.GetPropertyDescriptor(pd);
                if (descriptor != null)
                {
                    descriptor.SetValue(current, convertedValue);
                }
                else
                {
                    this.SetValue(owner, cell, convertedValue);

                    if (!(owner.ItemsSource is INotifyCollectionChanged))
                    {
                        owner.UpdateCellContent(cell);
                    }
                }

                return(true);
            }

            return(false);
        }