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

查看:31
本文介绍了从代码中获取 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天全站免登陆