微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

有没有办法使用像App.Current这样的代码来访问它?

解决方法

看看 the source code for WP7DataCollector.GetAppAttribute()在 Microsoft Silverlight Analytics Framework. GetAppAttribute(“标题”)会做到这一点.

/// <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);
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐