0

Problem

I have an XML file with an array of items. I can correctly bind to the list of items and also to attributes on the node. However, I cannot get any sub elements bound and not sure what XPath or Path to use. How do I bind a sub-element of an array item to a DataGridColumn?

More details

I have a .rdl file, which is basically XML, and would like to add images in bulk, which SSRS doesn't do. To get around this I created a WPF application with an XmlDataProvider as so:

<UserControl.DataContext>
    <XmlDataProvider x:Name="dpReport" Source="MyFile.rdl" XPath="rd:Report/rd:EmbeddedImages/rd:EmbeddedImage" />
</UserControl.DataContext>

I had to add the rd prefix in the XAML and in the NameTable in the code-behind otherwise it wouldn't bind.

I have a DataGrid, which is binding to the list correctly, and a column which is binding to the attribute Name correctly. However, I would also like to bind to the MIMEType and ImageData sub-elements. How would I do this?

Simplified DataGrid Xaml

<DataGrid x:Name="lstImages" AutoGenerateColumns="False" ItemsSource="{Binding}" Grid.Row="2">
    <DataGrid.Columns>      
        <DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name,Mode=TwoWay}"/>
        <!-- MIMEType Here -->
    </DataGrid.Columns>
</DataGrid>

XPaths attempted:

I have attempted to use variants of the following Bindings:

<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=MIMEType}"/>
<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=MIMEType/text()}"/>
<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=/MIMEType[1]/text()}"/>
<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=MIMEType[1]/text()}"/>
<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=(/MIMEType/text())[0]}"/>
<DataGridTextColumn Header="MimeType" Binding="{Binding XPath=(MIMEType/text())[0]}"/>
2
  • You should read in your xaml to a c# bindable observable collection then bind to it Commented Nov 29, 2017 at 8:14
  • You forgot to post your actual XAML data. Commented Nov 29, 2017 at 11:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.