简体   繁体   中英

Single line when binding XmlDataProvider to ListView

I want to show XmlData within a ListView. The XmlDataProvider is filled correctly but the Listview only shows the first line. What do I have to change to show all lines inside the XmlDocument?

<Window.Resources>
    <XmlDataProvider x:Key="xmlData"/>
</Window.Resources>
<DockPanel>
    <ListView Padding="4">
        <ListView.ItemsSource>
            <Binding Source="{StaticResource xmlData}" XPath="*"/>
        </ListView.ItemsSource>
        <ListView.View>
            <GridView >
                <GridViewColumn Header="Info" Width="256" DisplayMemberBinding="{Binding XPath=Message}"/>
            </GridView>
        </ListView.View>
    </ListView>
</DockPanel>

In code behind:

private void RefreshList(XmlDocument doc)
{
    XmlDataProvider provider = (XmlDataProvider)FindResource("xmlData");
    provider.Document = doc;
    provider.Refresh();
}

Ok so I solved it this way:

  1. Add XPath to XmlDataProvider
  2. Using of Path=InnerText instead of XPath

See source below.

<Window.Resources>
    <XmlDataProvider x:Key="xmlData" XPath="//Prototype"/>
</Window.Resources>
<DockPanel>
    <ListView>
        <ListView.ItemsSource>
            <Binding Source="{StaticResource xmlData}" XPath="Message"/>
        </ListView.ItemsSource>
        <ListView.View>
            <GridView >
                <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=InnerText}"/>
            </GridView>
        </ListView.View>
    </ListView>
</DockPanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM