从代码获取Windows Phone 7应用程序标题 [英] Get the Windows Phone 7 Application Title from Code

查看:78
本文介绍了从代码获取Windows Phone 7应用程序标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

是否可以使用App.Current之类的代码从代码中访问此内容?

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

推荐答案

查看 Microsoft Silverlight Analytics Framework 中WP7DataCollector.GetAppAttribute()的源代码. GetAppAttribute("Title")可以做到.

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

这篇关于从代码获取Windows Phone 7应用程序标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆