Building A List of Types That Have Content Properties

For future reference, here’s a little code snippet that iterates through all types in a Silverlight/WPF DLL and generates a list of types that have a XAML content property.  The list is written out to a file.

As an example, we generate the list for PresentationFramework.dll, which is where the Button type resides.

 // Click handler for a System.Windows.Controls.Button
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     ContentPropsInAssembly(button1.GetType().Assembly, "PresentationFramework.txt");
 }

 private void ContentPropsInAssembly(Assembly assem, string filename)
 {
     SortedDictionary<string, string> dictContentProps = new SortedDictionary<string, string>();

     // Iterate through every type in the assembly, recording those
     // that have content properties.
     foreach (Type nextType in assem.GetTypes())
     {
         ContentPropertyOfType(nextType, ref dictContentProps);
     }

     // Serialize
     using (StreamWriter sw = new StreamWriter(filename))
     {
         foreach (KeyValuePair<string, string> entry in dictContentProps)
             sw.WriteLine(string.Format("{0},{1}", entry.Key, entry.Value));
     }
 }

 // For a given type, determine if it has a content property.  If so, add the name
 // of the type and its content property to a dictionary.
 private void ContentPropertyOfType(Type t, ref SortedDictionary<string, string> dict)
 {
     foreach (object att in t.GetCustomAttributes(true))
     {
         Type attType = att.GetType();
         if (string.Equals(attType.Name, "ContentPropertyAttribute"))
         {
             ContentPropertyAttribute cpa = (ContentPropertyAttribute)att;
             dict.Add(t.FullName, cpa.Name);
             break;
         }
     }
 }

Also for the record, here is the full list of types in PresentationFramework.dll that have content properties, of the format [typename],[propertyname]

MS.Internal.Annotations.Component.HighlightComponent,Children
MS.Internal.Annotations.Component.MarkedHighlightComponent,Children
MS.Internal.AppModel.RootBrowserWindow,
MS.Internal.Controls.InkCanvasInnerCanvas,Children
MS.Internal.Documents.DocumentGridContextMenu+EditorMenuItem,Items
MS.Internal.Documents.DocumentGridContextMenu+ViewerContextMenu,Items
MS.Internal.Documents.ReaderPageViewer,Document
MS.Internal.Documents.ReaderScrollViewer,Document
MS.Internal.Documents.ReaderTwoPageViewer,Document
System.Windows.Controls.AccessText,Text
System.Windows.Controls.AdornedElementPlaceholder,Child
System.Windows.Controls.AlternationConverter,Values
System.Windows.Controls.Border,Child
System.Windows.Controls.Button,Content
System.Windows.Controls.Canvas,Children
System.Windows.Controls.CheckBox,Content
System.Windows.Controls.ComboBox,Items
System.Windows.Controls.ComboBoxItem,Content
System.Windows.Controls.ContentControl,Content
System.Windows.Controls.ContentPresenter+DefaultTemplate,VisualTree
System.Windows.Controls.ContentPresenter+UseContentTemplate,VisualTree
System.Windows.Controls.ContextMenu,Items
System.Windows.Controls.ControlTemplate,VisualTree
System.Windows.Controls.DataGrid,Items
System.Windows.Controls.DataGridCell,Content
System.Windows.Controls.DataGridCellsPanel,Children
System.Windows.Controls.DataGridComboBoxColumn+TextBlockComboBox,Items
System.Windows.Controls.Decorator,Child
System.Windows.Controls.DockPanel,Children
System.Windows.Controls.DocumentViewer,Document
System.Windows.Controls.Expander,Content
System.Windows.Controls.FlowDocumentPageViewer,Document
System.Windows.Controls.FlowDocumentReader,Document
System.Windows.Controls.FlowDocumentScrollViewer,Document
System.Windows.Controls.Frame,
System.Windows.Controls.Grid,Children
System.Windows.Controls.GridView,Columns
System.Windows.Controls.GridViewColumn,Header
System.Windows.Controls.GridViewColumnHeader,Content
System.Windows.Controls.GroupBox,Content
System.Windows.Controls.GroupItem,Content
System.Windows.Controls.HeaderedContentControl,Content
System.Windows.Controls.HeaderedItemsControl,Items
System.Windows.Controls.InkCanvas,Children
System.Windows.Controls.InkPresenter,Child
System.Windows.Controls.ItemContainerGenerator+EmptyGroupItem,Content
System.Windows.Controls.ItemsControl,Items
System.Windows.Controls.ItemsPanelTemplate,VisualTree
System.Windows.Controls.Label,Content
System.Windows.Controls.ListBox,Items
System.Windows.Controls.ListBoxItem,Content
System.Windows.Controls.ListView,Items
System.Windows.Controls.ListViewItem,Content
System.Windows.Controls.Menu,Items
System.Windows.Controls.MenuItem,Items
System.Windows.Controls.Page,Content
System.Windows.Controls.Panel,Children
System.Windows.Controls.Primitives.BulletDecorator,Child
System.Windows.Controls.Primitives.ButtonBase,Content
System.Windows.Controls.Primitives.CalendarButton,Content
System.Windows.Controls.Primitives.CalendarDayButton,Content
System.Windows.Controls.Primitives.DataGridCellsPresenter,Items
System.Windows.Controls.Primitives.DataGridColumnHeader,Content
System.Windows.Controls.Primitives.DataGridColumnHeadersPresenter,Items
System.Windows.Controls.Primitives.DataGridRowHeader,Content
System.Windows.Controls.Primitives.DataGridRowsPresenter,Children
System.Windows.Controls.Primitives.DatePickerTextBox,Text
System.Windows.Controls.Primitives.DocumentViewerBase,Document
System.Windows.Controls.Primitives.MenuBase,Items
System.Windows.Controls.Primitives.MultiSelector,Items
System.Windows.Controls.Primitives.Popup,Child
System.Windows.Controls.Primitives.RepeatButton,Content
System.Windows.Controls.Primitives.SelectiveScrollingGrid,Children
System.Windows.Controls.Primitives.Selector,Items
System.Windows.Controls.Primitives.StatusBar,Items
System.Windows.Controls.Primitives.StatusBarItem,Content
System.Windows.Controls.Primitives.TabPanel,Children
System.Windows.Controls.Primitives.ToggleButton,Content
System.Windows.Controls.Primitives.ToolBarOverflowPanel,Children
System.Windows.Controls.Primitives.ToolBarPanel,Children
System.Windows.Controls.Primitives.UniformGrid,Children
System.Windows.Controls.RadioButton,Content
System.Windows.Controls.RichTextBox,Document
System.Windows.Controls.ScrollViewer,Content
System.Windows.Controls.StackPanel,Children
System.Windows.Controls.TabControl,Items
System.Windows.Controls.TabItem,Content
System.Windows.Controls.TextBlock,Inlines
System.Windows.Controls.TextBox,Text
System.Windows.Controls.ToolBar,Items
System.Windows.Controls.ToolBarTray,ToolBars
System.Windows.Controls.ToolTip,Content
System.Windows.Controls.TreeView,Items
System.Windows.Controls.TreeViewItem,Items
System.Windows.Controls.UserControl,Content
System.Windows.Controls.Viewbox,Child
System.Windows.Controls.Viewport3D,Children
System.Windows.Controls.VirtualizingPanel,Children
System.Windows.Controls.VirtualizingStackPanel,Children
System.Windows.Controls.WrapPanel,Children
System.Windows.Data.MultiBinding,Bindings
System.Windows.Data.PriorityBinding,Bindings
System.Windows.Data.XmlDataProvider,XmlSerializer
System.Windows.DataTemplate,VisualTree
System.Windows.DataTrigger,Setters
System.Windows.Documents.AdornerDecorator,Child
System.Windows.Documents.AnchoredBlock,Blocks
System.Windows.Documents.BlockUIContainer,Child
System.Windows.Documents.Bold,Inlines
System.Windows.Documents.DocumentStructures.StoryFragment,BlockElementList
System.Windows.Documents.DocumentStructures.StoryFragments,StoryFragmentList
System.Windows.Documents.Figure,Blocks
System.Windows.Documents.FixedDocument,Pages
System.Windows.Documents.FixedDocumentSequence,References
System.Windows.Documents.FixedPage,Children
System.Windows.Documents.Floater,Blocks
System.Windows.Documents.FlowDocument,Blocks
System.Windows.Documents.Hyperlink,Inlines
System.Windows.Documents.InlineUIContainer,Child
System.Windows.Documents.Italic,Inlines
System.Windows.Documents.List,ListItems
System.Windows.Documents.ListItem,Blocks
System.Windows.Documents.NonLogicalAdornerDecorator,Child
System.Windows.Documents.PageContent,Child
System.Windows.Documents.Paragraph,Inlines
System.Windows.Documents.Run,Text
System.Windows.Documents.Section,Blocks
System.Windows.Documents.Span,Inlines
System.Windows.Documents.Table,RowGroups
System.Windows.Documents.TableCell,Blocks
System.Windows.Documents.TableRow,Cells
System.Windows.Documents.TableRowGroup,Rows
System.Windows.Documents.TextEditorContextMenu+EditorContextMenu,Items
System.Windows.Documents.TextEditorContextMenu+EditorMenuItem,Items
System.Windows.Documents.TextEditorContextMenu+ReconversionMenuItem,Items
System.Windows.Documents.Underline,Inlines
System.Windows.EventTrigger,Actions
System.Windows.FrameworkTemplate,VisualTree
System.Windows.HierarchicalDataTemplate,VisualTree
System.Windows.Media.Animation.BeginStoryboard,Storyboard
System.Windows.Media.Animation.Storyboard,Children
System.Windows.Media.Animation.ThicknessAnimationUsingKeyFrames,KeyFrames
System.Windows.MultiDataTrigger,Setters
System.Windows.MultiTrigger,Setters
System.Windows.Navigation.NavigationWindow,
System.Windows.Navigation.PageFunction`1,Content
System.Windows.Navigation.PageFunctionBase,Content
System.Windows.Shell.JumpList,JumpItems
System.Windows.Style,Setters
System.Windows.Trigger,Setters
System.Windows.VisualState,Storyboard
System.Windows.VisualStateGroup,States
System.Windows.VisualTransition,Storyboard
System.Windows.Window,Content

Advertisements

One thought on “Building A List of Types That Have Content Properties

  1. Pingback: #79 – Content Properties for Common WPF Types « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s