在WPF Application.ProductName相同呢? [英] Application.ProductName equivalent in WPF?

查看:620
本文介绍了在WPF Application.ProductName相同呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套在一个主界面适用的两个+层,即嵌套的类库我希望能够进入主应用程序的名称中的一个类库。

I have a class library that is nested two+ layers under a main GUI application, within that nested class library I want to be able to access the main applications name.

在NET 3.5的你可以调用Application.ProductName检索来自Assembly.cs文件中的值,但我不能确定在WPF等效。如果我使用反射和GetExecutingAssembly则返回类库细节?

Under .Net 3.5 you could call Application.ProductName to retrieve the value from the Assembly.cs file, but I cannot identify an equivalent in WPF. If I use reflection and GetExecutingAssembly then it returns the class libraries details?

感谢

推荐答案

您可以使用 Assembly.GetEntryAssembly()来获得EXE程序集,然后可以使用反射从获得AssemblyProductAttribute。

You can use Assembly.GetEntryAssembly() to get the EXE assembly, and can then use Reflection to get the AssemblyProductAttribute from that.

这假定产品名称已定的EXE组件。在的WinForms Application.ProductName 属性实际上看着含有的主要形式装配的,所以它的工作原理,即使GUI是建立在一个DLL。在WPF复制此你可以使用 Application.Current.MainWindow.GetType()。大会(并再次使用反射来获取属性)。

This assumes that the product name has been set on the EXE assembly. The WinForms Application.ProductName property actually looked in the assembly containing the main form, so it works even if the GUI is built in a DLL. To replicate this in WPF you would use Application.Current.MainWindow.GetType().Assembly (and again use Reflection to get the attribute).

这篇关于在WPF Application.ProductName相同呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆