【问题标题】:Getting the exact display name of the metro style apps获取 Metro 风格应用程序的确切显示名称
【发布时间】:2016-07-22 09:57:39
【问题描述】:

我正在使用PackageManager 类列出系统中已安装的 Metro 风格应用程序。

PackageId.Name 不返回包的实际名称,Package.DisplayName 也不返回。 Package.DisplayName 返回空字符串。它只返回 Package.Current 的显示名称。

当我尝试使用 AppxManifest.xml 时,我无法从
获取显示名称 包-> 属性-> 显示名称。

<Properties>
<DisplayName>ms-resource:///Resources/AppStoreName</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Assets\WindowsIcons\StoreLogo.png</Logo>
</Properties>

我在哪里可以获得 Metro 风格应用程序的确切显示名称?

【问题讨论】:

    标签: c# .net microsoft-metro windows-10


    【解决方案1】:

    如果您已经引用了 Package 实例,则可以使用互操作方法和注册表获取显示名称。这是一个完整的例子:

    using Microsoft.Win32;
    using System;
    using System.Runtime.InteropServices;
    using System.Text;
    using Windows.ApplicationModel;
    
    public class PackageUtil
    {
        [DllImport("shlwapi.dll", BestFitMapping = false, CharSet = CharSet.Unicode, 
            ExactSpelling = true, SetLastError = false, ThrowOnUnmappableChar = true)]
    
        private static extern int SHLoadIndirectString(string pszSource, 
            StringBuilder pszOutBuf, int cchOutBuf, IntPtr ppvReserved);
    
        private static string GetPackageDisplayName(Package package)
        {
            using (var key = Registry.ClassesRoot.OpenSubKey(
                @"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel" + 
                $@"\Repository\Packages\{package.Id.FullName}\App\Capabilities"))
            {
                var sb = new StringBuilder(256);
                Shlwapi.SHLoadIndirectString((string)key.GetValue("ApplicationName"), 
                    sb, sb.Capacity, IntPtr.Zero);
                return sb.ToString();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多