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

前端之家收集整理的这篇文章主要介绍了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);
        }
    }

猜你在找的Silverlight相关文章