protected DataGridItemProperty(DataGridItemProperty template)
     : base(template)
 {
     // this.IsAutoCreated = false, after a clone, we consider the ItemProperty not AutoCreated.
     m_propertyDescriptor = template.m_propertyDescriptor;
     m_valueXPath         = template.m_valueXPath;
     m_valuePath          = template.m_valuePath;
 }
示例#2
0
 public PropertyDescriptorFromItemProperty(DataGridItemProperty dataGridItemProperty)
     : base(dataGridItemProperty)
 {
     m_propertyDescriptorForValueChanged = dataGridItemProperty.PropertyDescriptor;
 }
        internal override void SetUnspecifiedPropertiesValues(DataGridItemPropertyCollection itemPropertyCollection)
        {
            // ContainingCollection.ItemType and ContainingCollection.DefaultItemProperties can be null at first when this is
            // the ItemProperties of a DetailGrid.
            // the SetUnspecifiedPropertiesValues will be recall when both this.ItemType and this.DefaultItemProperties are affected.

            if (itemPropertyCollection == null)
            {
                return;
            }

            DataGridItemProperty defaultItemProperty = null;
            bool itemIsNequeoDataRow = (itemPropertyCollection.ItemType != null) ? typeof(DataRow).IsAssignableFrom(itemPropertyCollection.ItemType) : false;

            if ((string.IsNullOrEmpty(this.ValueXPath)) &&
                (string.IsNullOrEmpty(this.ValuePath)) &&
                (this.PropertyDescriptor == null))
            {
                if (itemIsNequeoDataRow)
                {
                    this.PropertyDescriptor = new UnboundDataRowPropertyDescriptor(this.Name, this.DataType);
                }
                else
                {
                    defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;

                    if (defaultItemProperty == null)
                    {
                        if (this.Name == ".")
                        {
                            this.SetPropertyDescriptor(new SelfPropertyDescriptor(this.DataType));
                            this.SetValuePath(".");
                            this.SetIsReadOnly(true);
                            this.SetOverrideReadOnlyForInsertion(false);
                        }
                        else if (itemPropertyCollection.DefaultItemProperties != null)
                        {
                            // I have to add this particular exception case to make sure that when the ItemProperty is "re-normalized" when the first DataGridCollectionView
                            // is created for it, then the ValuePath is still null or empty (allowing it to be re-normalized)
                            this.SetValuePath(this.Name);
                        }
                    }
                    else
                    {
                        this.SetPropertyDescriptor(defaultItemProperty.PropertyDescriptor);
                        this.SetValuePath(defaultItemProperty.ValuePath);
                        this.SetValueXPath(defaultItemProperty.ValueXPath);
                    }
                }
            }

            if (this.DataType == null)
            {
                //only try to affect the DataType if the DefaultItemProperties were set. (will not be the case when XAML parsing DetailDescriptions)
                if (itemPropertyCollection.DefaultItemProperties != null)
                {
                    if (defaultItemProperty == null)
                    {
                        defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;
                    }

                    if (defaultItemProperty == null)
                    {
                        throw new InvalidOperationException("An attempt was made to add an item (" + this.Name + ") without specifying its data type.");
                    }

                    this.SetDataType(defaultItemProperty.DataType);
                }
            }

            if (string.IsNullOrEmpty(this.Title))
            {
                if (itemIsNequeoDataRow)
                {
                    this.Title = this.Name;
                }
                else
                {
                    if (defaultItemProperty == null)
                    {
                        defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;
                    }

                    if (defaultItemProperty == null)
                    {
                        this.Title = this.Name;
                    }
                    else
                    {
                        this.Title = defaultItemProperty.Title;
                    }
                }
            }

            if (!this.IsReadOnly)
            {
                if (defaultItemProperty == null)
                {
                    defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;
                }

                if (defaultItemProperty != null)
                {
                    this.SetIsReadOnly(defaultItemProperty.IsReadOnly);
                }
            }

            if (this.OverrideReadOnlyForInsertion == null)
            {
                //only try to affect the DataType if the DefaultItemProperties were set. (will not be the case when XAML parsing DetailDescriptions)
                if (itemPropertyCollection.DefaultItemProperties != null)
                {
                    if (defaultItemProperty == null)
                    {
                        defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;
                    }

                    this.SetOverrideReadOnlyForInsertion((defaultItemProperty != null) && (defaultItemProperty.OverrideReadOnlyForInsertion.HasValue)
            ? defaultItemProperty.OverrideReadOnlyForInsertion.Value
            : false);
                }
            }

            if ((!string.IsNullOrEmpty(this.ValueXPath)) && (string.IsNullOrEmpty(this.ValuePath)))
            {
                this.SetValuePath("InnerText");
            }

            bool foreignKeyDescriptionIsNull            = (this.ForeignKeyDescription == null);
            bool foreignKeyDescriptionItemsSourceIsNull = false;

            if (!foreignKeyDescriptionIsNull)
            {
                foreignKeyDescriptionItemsSourceIsNull = (this.ForeignKeyDescription.ItemsSource == null);
            }

            // Update the ForeignKeyDescription if not set
            if (foreignKeyDescriptionIsNull || foreignKeyDescriptionItemsSourceIsNull)
            {
                if (defaultItemProperty == null)
                {
                    defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty;
                }

                if ((defaultItemProperty != null) && (defaultItemProperty.ForeignKeyDescription != null))
                {
                    if (foreignKeyDescriptionIsNull)
                    {
                        this.SetForeignKeyDescription(defaultItemProperty.ForeignKeyDescription);
                    }
                    else
                    {
                        if (foreignKeyDescriptionItemsSourceIsNull)
                        {
                            this.ForeignKeyDescription.ItemsSource = defaultItemProperty.ForeignKeyDescription.ItemsSource;
                        }
                    }
                }
            }
        }