コード例 #1
0
        private void RefreshQuickTypes()
        {
            bool previousValue = IgnoreInternalChanges();

            try
            {
                _quickTypeCollection.Clear();

                PropertyEntry containedProperty = this.PropertyEntry;
                if (containedProperty == null)
                {
                    return;
                }

                ModelProperty           property             = ((ModelPropertyEntry)containedProperty).FirstModelProperty;
                Type                    containerValueType   = ((ModelPropertyEntryBase)containedProperty).CommonValueType;
                NewItemFactoryTypeModel selectedFactoryModel = null;
                Type                    defaultItemType      = GetDefaultItemType(property);

                // Find all elligible NewItemFactoryTypes declared through metadata
                IEnumerable <NewItemFactoryTypeModel> factoryModels =
                    ExtensibilityAccessor.GetNewItemFactoryTypeModels(
                        property,
                        ResourceUtilities.GetDesiredTypeIconSize(this));

                if (factoryModels != null)
                {
                    foreach (NewItemFactoryTypeModel factoryModel in factoryModels)
                    {
                        _quickTypeCollection.Add(factoryModel);

                        if (selectedFactoryModel == null)
                        {
                            if (object.Equals(containerValueType, factoryModel.Type))
                            {
                                selectedFactoryModel = factoryModel;
                            }
                        }

                        if (defaultItemType != null &&
                            object.Equals(defaultItemType, factoryModel.Type))
                        {
                            defaultItemType = null;
                        }
                    }
                }

                //add a null value - user should always have an option to clear property value
                NewItemFactoryTypeModel nullTypeFactoryTypeModel =
                    new NewItemFactoryTypeModel(null, new NullItemFactory());

                // Add a default item type based on the property type (if it wasn't also added through
                // metadata)
                if (defaultItemType != null)
                {
                    NewItemFactoryTypeModel defaultItemFactoryTypeModel = new NewItemFactoryTypeModel(defaultItemType, new NewItemFactory());
                    _quickTypeCollection.Add(defaultItemFactoryTypeModel);

                    if (selectedFactoryModel == null)
                    {
                        if (object.Equals(containerValueType, defaultItemFactoryTypeModel.Type))
                        {
                            selectedFactoryModel = defaultItemFactoryTypeModel;
                        }
                        else if (containerValueType == null)
                        {
                            selectedFactoryModel = nullTypeFactoryTypeModel;
                        }
                    }
                }

                _quickTypeCollection.Add(nullTypeFactoryTypeModel);

                // Make sure the currently selected value on the CollectionView reflects the
                // actual value of the property
                _quickTypeView.MoveCurrentTo(selectedFactoryModel);
                this.CurrentQuickType = selectedFactoryModel;
            }
            finally
            {
                NoticeInternalChanges(previousValue);
            }
        }