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", "开发者_C百科ListBox" etc.
Any help would be much appreciated!
Kris
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.
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.
var names = typeof(FrameworkElement)
.Assembly
.GetExportedTypes()
.Where(x => x.IsSubclassOf(typeof(FrameworkElement)))
.Select(x => x.Name);
加载中,请稍侯......
精彩评论