WPF读取XML文件

XPath语法:http://www.w3school.com.cn/xpath/xpath_syntax.asp

XML

<Cities>

  <City>

    <CityName>北京</CityName>

  </City>

  <City>

    <CityName>上海</CityName>

  </City>

  <City>

    <CityName>广州</CityName>

  </City>

</Cities>

XAML

<Window.Resources>

        <XmlDataProvider x:Key="DataInfo" Source="/XMLS/Data.xml" XPath="Cities" />

    </Window.Resources>

    <Grid>

        <ListBox Width="100" Height="100" ItemsSource="{Binding XPath=City, Source={StaticResource DataInfo}}" />

    </Grid>

你可能感兴趣的:(读取xml)