silverlight - 从代码获取Windows Phone 7应用程序标题

标签 silverlight windows-phone-7 manifest

我想从我的ViewModel代码访问WMAppManifest.xml文件中存储的Title值。这是通过项目属性设置的相同应用程序标题。

有没有办法使用App.Current之类的代码从代码中访问它?

最佳答案

the source code中查看WP7 DataCollector.GetApp Attribute()的ojota。 GetAppAttribute(“Title”)可以做到。

    /// <summary>
    /// Gets an attribute from the Windows Phone App Manifest App element
    /// </summary>
    /// <param name="attributeName">the attribute name</param>
    /// <returns>the attribute value</returns>
    private static string GetAppAttribute(string attributeName)
    {
        string appManifestName = "WMAppManifest.xml";
        string appNodeName = "App";

        var settings = new XmlReaderSettings();
        settings.XmlResolver = new XmlXapResolver();

        using (XmlReader rdr = XmlReader.Create(appManifestName, settings))
        {
            rdr.ReadToDescendant(appNodeName);
            if (!rdr.IsStartElement())
            {
                throw new System.FormatException(appManifestName + " is missing " + appNodeName);
            }

            return rdr.GetAttribute(attributeName);
        }
    }

关于silverlight - 从代码获取Windows Phone 7应用程序标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3411377/

相关文章:

python - 如何向 PyInstaller 编译的 EXE 添加 list ?

java - 大文件下载

silverlight - 使用调试运行项目需要很长时间才能加载

windows-phone-7 - 如何在 wp7 中的列表框项目之间插入特定数量的空间?

c# - MVVM + 多级/嵌套数据绑定(bind)

com - 从 Powerbuilder 应用程序调用 .Net COM 程序集(无需注册)

java - 在manifest文件中怎么写呢?

wcf - 需要从保存登录客户端的 cookie 中检索数据

c# - 在 Silverlight (C#) 中访问 MySQL 数据库

c# - 保护条款不触发