如何以编程方式从属性中获取我的Windows 8应用程序名称?

时间:2013-01-20 12:53:31

标签: c# windows-8 windows-runtime manifest title

我需要将Windows 8应用程序名称添加到变量中,但我找不到这样做的方法。

我想从应用程序属性中获取标题(“ TEMEL UYGULAMA ”),如此屏幕截图所示:http://prntscr.com/psd6w

或者,如果有人知道获取应用程序名称或标题,我可以使用它。我只需要获取应用名称或标题(在程序集内)

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

从截图中,您似乎想要装配标题。您可以通过执行以下操作在运行时获取程序集标题属性:

// Get current assembly
var thisAssembly = this.GetType().Assembly;

// Get title attribute (on .NET 4)
var titleAttribute = thisAssembly
        .GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
        .Cast<AssemblyTitleAttribute>()
        .FirstOrDefault();

// Get title attribute (on .NET 4.5)
var titleAttribute = thisAssembly.GetCustomAttribute<AssemblyTitleAttribute>();

if (titleAttribute != null)
{
    var title = titleAttribute.Title;
    // Do something with title...
}

但请记住,这是应用程序名称,这是程序集标题。

答案 1 :(得分:0)

我使用这样的代码来获取 Windows应用商店程序集的Title 属性

首先,您需要这些程序集:

using System.Reflection;
using System.Linq;

...然后这样的代码应该可以工作(可能有更多的检查):

// Get the assembly with Reflection:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;

// Get the custom attribute informations:
var titleAttribute = assembly.CustomAttributes.Where(ca => ca.AttributeType == typeof(AssemblyTitleAttribute)).FirstOrDefault();

// Now get the string value contained in the constructor:
return titleAttribute.ConstructorArguments[0].Value.ToString();

希望这会有所帮助......

相关问题