开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜