我有以下xml doc作为我的数据源:
<?xml version="1.0" encoding="utf-8" ?>
<AccessLauncherCentralConfig>
<DataTablesForExport>
<Table>Unit1.Alarm</Table>
<Table>Unit1.Alarm Categories</Table>
<Table>Unit1.Alarms Analogue</Table>
</DataTablesForExport>
<SqlDbServer>localhost</SqlDbServer>
</AccessLauncherCentralConfig>
我有以下xaml:
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="ConfigData" Source="CentralConfig.xml" XPath="/"/>
</Grid.Resources>
<DataGrid x:Name="dgridEmp" ItemsSource="{Binding Source={StaticResource ConfigData}, XPath=AccessLauncherCentralConfig}"
AutoGenerateColumns="False" Margin="52,89,31,50">
<DataGrid.Columns>
<DataGridTextColumn Header="Tables For Export" Binding="{Binding XPath=DataTablesForExport/Table}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
为什么网格只显示第一行(Unit1.Alarm)?
答案 0 :(得分:1)
您的XPaths
无效。试试这个:
<DataGrid x:Name="dgridEmp"
ItemsSource="{Binding Source={StaticResource ConfigData}, XPath=AccessLauncherCentralConfig/DataTablesForExport/Table}"
AutoGenerateColumns="False" Margin="52,89,31,50">
<DataGrid.Columns>
<DataGridTextColumn Header="Tables For Export" Binding="{Binding XPath=.}" />
</DataGrid.Columns>
</DataGrid>
它将显示三行。