【问题标题】:How to parse a xaml file/string如何解析 xaml 文件/字符串
【发布时间】:2012-06-11 00:12:43
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c# wpf xml


    【解决方案1】:

    MSDN 文档显示使用 XmlReader 作为 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 来获取属性。

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

    您将在 MSDN 示例中显示的 switch 语句中使用 XmlNodeType.Attribute,首先在 XmlNodeType.Element 案例中注明您所在的节点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-18
      • 2022-01-14
      • 2014-05-24
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      相关资源
      最近更新 更多