lookitskris
lookitskris

Reputation: 678

Programatically retrieve a list of the Controls that ship with .NET 4.0

What I am looking to do is create a list of all the WPF controls that ship with .NET 4. Ideally, this list would need to be a collection of string objects of items like "Button", "ListBox" etc.

Any help would be much appreciated!

Kris

Upvotes: 0

Views: 95

Answers (3)

Thomas Levesque
Thomas Levesque

Reputation: 292695

This will retrieve all subclasses of FrameworkElement in the PresentationFramework assembly

var query =
    from type in typeof(FrameworkElement).Assembly.GetTypes()
    where type.IsSubclassOf(typeof(FrameworkElement))
    select type.Name;

List<string> controls = query.ToList();

Note: there isn't a very clear definition of what is a "control" in WPF... there is a Control class, but not all UI elements inherit from it. Most "controls" inherit (directly or indirectly) from FrameworkElement.

Upvotes: 4

mathieu
mathieu

Reputation: 31192

var names = typeof(FrameworkElement)
    .Assembly
    .GetExportedTypes()
    .Where(x => x.IsSubclassOf(typeof(FrameworkElement)))
    .Select(x => x.Name);

Upvotes: 0

Matti Virkkunen
Matti Virkkunen

Reputation: 65166

If you really want all of them, you could search through the relevant assemblies using reflection and find any concrete classes that inherit from the control base class.

Upvotes: 0

Related Questions