如何解析 xaml 文件/字符串 [英] How to parse a xaml file/string

查看:49
本文介绍了如何解析 xaml 文件/字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XamlReader() 读取一个 xaml 文件,它当然具有元素和属性,例如:

I'm reading an xaml file using XamlReader() and it has of course elements and attributes such as:

<setter property="Property1" Value="Value1" />

是否有任何方法可以定位特定属性及其关联值?

Are there any methods to locate a specific property and its associated value?

我应该使用字符串函数解析字符串吗?

Should I parse the string using string functions?

推荐答案

MSDN 文档显示使用 XmlReader 作为 XamlReader 的输入

The MSDN docs show using an XmlReader as input to XamlReader

// Load the button
StringReader stringReader = new StringReader(savedButton);
XmlReader xmlReader = XmlReader.Create(stringReader);
Button readerLoadButton = (Button)XamlReader.Load(xmlReader);

http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

您可以只使用 XmlReader 来获取属性.

You could just use the XmlReader to grab attributes.

http://msdn.microsoft.com/en-us/library/cc189056%28VS.95%29.aspx

您可以在 MSDN 示例中显示的 switch 语句中使用 XmlNodeType.Attribute,首先在 XmlNodeType.Element 中注意您所在的节点后 案例.

You would use XmlNodeType.Attribute in the switch statement shown in the MSDN example, after first noting the node you're in in the XmlNodeType.Element case.

这篇关于如何解析 xaml 文件/字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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