views:

57

answers:

1

I want to access the Title value that is stored in the WMAppManifest.xml file from my ViewModel code. This is the same application title that is set through the project properties.

Is there a way to access this from code using something like App.Current?

+2  A: 

Look at the source code for WP7DataCollector.GetAppAttribute() in the Microsoft Silverlight Analytics Framework. GetAppAttribute("Title") will do it.

    /// <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);
        }
    }
Michael S. Scherotter