public MainPage() { this.InitializeComponent(); highlightBrush = this.Resources["ApplicationPressedForegroundThemeBrush"] as Brush; // Accumulate all the classes that derive from DependencyObject AddToClassList(typeof(Windows.UI.Xaml.DependencyObject)); // Sort them alphabetically by name classes.Sort((t1, t2) => { return(String.Compare(t1.GetTypeInfo().Name, t2.GetTypeInfo().Name)); }); // Put all these sorted classes into a tree structure ClassAndSubclasses rootClass = new ClassAndSubclasses(rootType); AddToTree(rootClass, classes); // Display the tree using TextBlock's added to StackPanel DisplayAndPrinterPrep(rootClass, 0); // Create PrintDocument and attach handlers printDocument = new PrintDocument(); printDocumentSource = printDocument.DocumentSource; printDocument.Paginate += OnPrintDocumentPaginate; printDocument.GetPreviewPage += OnPrintDocumentGetPreviewPage; printDocument.AddPages += OnPrintDocumentAddPages; }
void AddToTree(ClassAndSubclasses parentClass, List <Type> classes) { foreach (Type type in classes) { Type baseType = type.GetTypeInfo().BaseType; if (baseType == parentClass.Type) { ClassAndSubclasses subClass = new ClassAndSubclasses(type); parentClass.Subclasses.Add(subClass); AddToTree(subClass, classes); } } }
void DisplayAndPrinterPrep(ClassAndSubclasses parentClass, int indent) { TypeInfo typeInfo = parentClass.Type.GetTypeInfo(); // Create TextBlock and add to StackPanel TextBlock txtblk = CreateTextBlock(typeInfo, indent); stackPanel.Children.Add(txtblk); // Create TextBlock and add to printer list txtblk = CreateTextBlock(typeInfo, indent); txtblk.Foreground = blackBrush; printerTextBlocks.Add(txtblk); // Call this method recursively for all subclasses foreach (ClassAndSubclasses subclass in parentClass.Subclasses) { DisplayAndPrinterPrep(subclass, indent + 1); } }