0

Windows 8 アプリ名を変数に取得する必要がありますが、これを行う方法が見つかりません。

このスクリーンショットに示すように、アプリケーション プロパティからタイトル (" TEMEL UYGULAMA ")を取得したい: http://prntscr.com/psd6w

または、とにかくアプリケーション名またはタイトルを取得する方法を誰かが知っている場合は、それを使用できます。アプリ名またはタイトル (アセンブリ内) を取得する必要があるだけです

ご協力いただきありがとうございます。

4

2 に答える 2

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...
}

ただし、これはアプリケーション名ではなく、アセンブリ タイトルであることを忘れないでください。

于 2013-01-20T13:04:52.163 に答える
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();

お役に立てれば...

于 2013-08-30T10:23:29.263 に答える