我想从我的ViewModel代码访问WMAppManifest.xml文件中存储的Title值。这是通过项目属性设置的相同应用程序标题。
有没有办法使用App.Current之类的代码从代码中访问它?
最佳答案
在the source code中查看WP7 DataCollector.GetApp Attribute()的ojota。 GetAppAttribute(“Title”)可以做到。
/// <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 - 从代码获取Windows Phone 7应用程序标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3411377/