Mat*_*sto 10 silverlight manifest windows-phone-7
我想从我的ViewModel代码访问存储在WMAppManifest.xml文件中的Title值.这是通过项目属性设置的相同应用程序标题.
有没有办法从App.Current这样的代码访问代码?
Mic*_*ter 12
查看Microsoft Silverlight Analytics Framework中 WP7DataCollector.GetAppAttribute()的源代码.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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3241 次 |
| 最近记录: |