public static IDictionary <Type, IList <NewItemFactory> > GetNewItemFactoriesFromAttributes(IList <NewItemTypesAttribute> attributes, IMessageLoggingService exceptionLogger)
        {
            Dictionary <Type, IList <NewItemFactory> > dictionary = new Dictionary <Type, IList <NewItemFactory> >();

            using (IEnumerator <NewItemTypesAttribute> enumerator = ((IEnumerable <NewItemTypesAttribute>)attributes).GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    NewItemTypesAttribute current = enumerator.Current;
                    try
                    {
                        NewItemFactory newItemFactory = (NewItemFactory)Activator.CreateInstance(current.get_FactoryType());
                        if (newItemFactory != null)
                        {
                            foreach (Type key in current.get_Types())
                            {
                                IList <NewItemFactory> list;
                                if (!dictionary.TryGetValue(key, out list))
                                {
                                    list = (IList <NewItemFactory>) new List <NewItemFactory>();
                                    dictionary.Add(key, list);
                                }
                                ((ICollection <NewItemFactory>)list).Add(newItemFactory);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (exceptionLogger != null)
                        {
                            exceptionLogger.WriteLine(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.CollectionItemFactoryInstantiateFailed, new object[1]
                            {
                                (object)ExtensibilityMetadataHelper.GetExceptionMessage(ex)
                            }));
                        }
                    }
                }
            }
            return((IDictionary <Type, IList <NewItemFactory> >)dictionary);
        }
Example #2
0
        private void AddDataGridAttributes()
        {
            AddCallback(
                typeof(DataGrid),
                delegate(AttributeCallbackBuilder builder)
            {
                // Set the default property. The default event is inherited - SelectionChanged
                builder.AddCustomAttributes(new DefaultPropertyAttribute("Columns"));

                // In Blend these properties need to be browsable to be accessible from the CategoryEditor
                builder.AddCustomAttributes(DataGrid.AutoGenerateColumnsProperty, BrowsableAttribute.Yes);
                builder.AddCustomAttributes(DataGrid.ItemsSourceProperty, BrowsableAttribute.Yes);

                builder.AddCustomAttributes(DataGrid.CurrentCellProperty, BrowsableAttribute.No);
                builder.AddCustomAttributes(DataGrid.CurrentColumnProperty, BrowsableAttribute.No);
                builder.AddCustomAttributes(DataGrid.CurrentItemProperty, BrowsableAttribute.No);
                builder.AddCustomAttributes(DataGrid.RowStyleSelectorProperty, BrowsableAttribute.No);
                builder.AddCustomAttributes("SelectedItems", BrowsableAttribute.No);
                builder.AddCustomAttributes(DataGrid.RowDetailsTemplateSelectorProperty, BrowsableAttribute.No);
                builder.AddCustomAttributes(DataGrid.RowHeaderTemplateSelectorProperty, BrowsableAttribute.No);

                // Add Column types that can be added
                NewItemTypesAttribute attr = new NewItemTypesAttribute(
                    typeof(DataGridTextColumn),
                    typeof(DataGridCheckBoxColumn),
                    typeof(DataGridHyperlinkColumn),
                    typeof(DataGridComboBoxColumn),
                    typeof(DataGridTemplateColumn));
                attr.FactoryType = typeof(DataGridColumnFactory);
                builder.AddCustomAttributes("Columns", attr);

                // Enable addition of RowValidationRules
                builder.AddCustomAttributes("RowValidationRules", new NewItemTypesAttribute(typeof(ExceptionValidationRule), typeof(DataErrorValidationRule)));

                CategoryAttribute columnsCategory = new CategoryAttribute("Columns");
                builder.AddCustomAttributes(DataGrid.AutoGenerateColumnsProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserReorderColumnsProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserResizeColumnsProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserSortColumnsProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.CellStyleProperty, columnsCategory);
                builder.AddCustomAttributes("Columns", columnsCategory);
                builder.AddCustomAttributes(DataGrid.ColumnWidthProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.FrozenColumnCountProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.MaxColumnWidthProperty, columnsCategory);
                builder.AddCustomAttributes(DataGrid.MinColumnWidthProperty, columnsCategory);

                CategoryAttribute rowsCategory = new CategoryAttribute("Rows");
                builder.AddCustomAttributes(DataGrid.ItemsSourceProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.AlternationCountProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.AlternatingRowBackgroundProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.AreRowDetailsFrozenProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserAddRowsProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserDeleteRowsProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.CanUserResizeRowsProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.MinRowHeightProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowBackgroundProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowDetailsTemplateProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowDetailsVisibilityModeProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowHeightProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowStyleProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.RowValidationErrorTemplateProperty, rowsCategory);
                builder.AddCustomAttributes("RowValidationRules", rowsCategory);
                builder.AddCustomAttributes(DataGrid.SelectionModeProperty, rowsCategory);
                builder.AddCustomAttributes(DataGrid.SelectionUnitProperty, rowsCategory);

                CategoryAttribute headersCategory = new CategoryAttribute("Headers");
                builder.AddCustomAttributes(DataGrid.ColumnHeaderHeightProperty, headersCategory);
                builder.AddCustomAttributes(DataGrid.ColumnHeaderStyleProperty, headersCategory);
                builder.AddCustomAttributes(DataGrid.HeadersVisibilityProperty, headersCategory);
                builder.AddCustomAttributes(DataGrid.RowHeaderTemplateProperty, headersCategory);
                builder.AddCustomAttributes(DataGrid.RowHeaderStyleProperty, headersCategory);
                builder.AddCustomAttributes(DataGrid.RowHeaderWidthProperty, headersCategory);

                CategoryAttribute gridLinesCategory = new CategoryAttribute("Grid Lines");
                builder.AddCustomAttributes(DataGrid.GridLinesVisibilityProperty, gridLinesCategory);
                builder.AddCustomAttributes(DataGrid.HorizontalGridLinesBrushProperty, gridLinesCategory);
                builder.AddCustomAttributes(DataGrid.VerticalGridLinesBrushProperty, gridLinesCategory);
            });
        }
        private void AddDataGridAttributes() 
        {
            AddCallback(
                typeof(DataGrid), 
                delegate(AttributeCallbackBuilder builder) 
                {
                    // Set the default property. The default event is inherited - SelectionChanged
                    builder.AddCustomAttributes(new DefaultPropertyAttribute("Columns"));

                    // In Blend these properties need to be browsable to be accessible from the CategoryEditor
                    builder.AddCustomAttributes(DataGrid.AutoGenerateColumnsProperty, BrowsableAttribute.Yes);
                    builder.AddCustomAttributes(DataGrid.ItemsSourceProperty, BrowsableAttribute.Yes);

                    builder.AddCustomAttributes(DataGrid.CurrentCellProperty, BrowsableAttribute.No);
                    builder.AddCustomAttributes(DataGrid.CurrentColumnProperty, BrowsableAttribute.No);
                    builder.AddCustomAttributes(DataGrid.CurrentItemProperty, BrowsableAttribute.No);
                    builder.AddCustomAttributes(DataGrid.RowStyleSelectorProperty, BrowsableAttribute.No);
                    builder.AddCustomAttributes("SelectedItems", BrowsableAttribute.No);
                    builder.AddCustomAttributes(DataGrid.RowDetailsTemplateSelectorProperty, BrowsableAttribute.No);
                    builder.AddCustomAttributes(DataGrid.RowHeaderTemplateSelectorProperty, BrowsableAttribute.No);

                    // Add Column types that can be added
                    NewItemTypesAttribute attr = new NewItemTypesAttribute(
                                                        typeof(DataGridTextColumn),
                                                        typeof(DataGridCheckBoxColumn),
                                                        typeof(DataGridHyperlinkColumn),
                                                        typeof(DataGridComboBoxColumn),
                                                        typeof(DataGridTemplateColumn));
                    attr.FactoryType = typeof(DataGridColumnFactory);
                    builder.AddCustomAttributes("Columns", attr);

                    // Enable addition of RowValidationRules
                    builder.AddCustomAttributes("RowValidationRules", new NewItemTypesAttribute(typeof(ExceptionValidationRule), typeof(DataErrorValidationRule)));

                    CategoryAttribute columnsCategory = new CategoryAttribute(SR.Get(SRID.ColumnsCategoryTitle));
                    builder.AddCustomAttributes(DataGrid.AutoGenerateColumnsProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserReorderColumnsProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserResizeColumnsProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserSortColumnsProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.CellStyleProperty, columnsCategory);
                    builder.AddCustomAttributes("Columns", columnsCategory);
                    builder.AddCustomAttributes(DataGrid.ColumnWidthProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.FrozenColumnCountProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.MaxColumnWidthProperty, columnsCategory);
                    builder.AddCustomAttributes(DataGrid.MinColumnWidthProperty, columnsCategory);

                    CategoryAttribute rowsCategory = new CategoryAttribute(SR.Get(SRID.RowsCategoryTitle));
                    builder.AddCustomAttributes(DataGrid.ItemsSourceProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.AlternationCountProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.AlternatingRowBackgroundProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.AreRowDetailsFrozenProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserAddRowsProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserDeleteRowsProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.CanUserResizeRowsProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.MinRowHeightProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowBackgroundProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowDetailsTemplateProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowDetailsVisibilityModeProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowHeightProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowStyleProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.RowValidationErrorTemplateProperty, rowsCategory);
                    builder.AddCustomAttributes("RowValidationRules", rowsCategory);
                    builder.AddCustomAttributes(DataGrid.SelectionModeProperty, rowsCategory);
                    builder.AddCustomAttributes(DataGrid.SelectionUnitProperty, rowsCategory);

                    CategoryAttribute headersCategory = new CategoryAttribute(SR.Get(SRID.HeadersCategoryTitle));
                    builder.AddCustomAttributes(DataGrid.ColumnHeaderHeightProperty, headersCategory);
                    builder.AddCustomAttributes(DataGrid.ColumnHeaderStyleProperty, headersCategory);
                    builder.AddCustomAttributes(DataGrid.HeadersVisibilityProperty, headersCategory);
                    builder.AddCustomAttributes(DataGrid.RowHeaderTemplateProperty, headersCategory);
                    builder.AddCustomAttributes(DataGrid.RowHeaderStyleProperty, headersCategory);
                    builder.AddCustomAttributes(DataGrid.RowHeaderWidthProperty, headersCategory);

                    CategoryAttribute gridLinesCategory = new CategoryAttribute(SR.Get(SRID.GridLinesCategoryTitle));
                    builder.AddCustomAttributes(DataGrid.GridLinesVisibilityProperty, gridLinesCategory);
                    builder.AddCustomAttributes(DataGrid.HorizontalGridLinesBrushProperty, gridLinesCategory);
                    builder.AddCustomAttributes(DataGrid.VerticalGridLinesBrushProperty, gridLinesCategory);
                });
        }