Reputation: 170
I'm rather new to WPF so please bear with me. I'm trying to bind an XML file to a TextBox so I can view the content and edit the file. I tried several suggestions already (SO, Google, ...) but I can't seem to get this working.
My XMLDataProvider looks like this:
<Window.Resources>
<XmlDataProvider x:Key="test" Source="U:\x\2616004.xml" />
</Window.Resources>
My TextBox is within a TabItem and looks like this:
<Grid Background="#FFE5E5E5">
<TextBox x:Name="tbBiblio" Background="White" HorizontalAlignment="Left" Height="548" Margin="7,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="773"
Text="{Binding Source={StaticResource test}, XPath=/*/}" />
</Grid>
If I run the application it just gives me an empty TextBox. I also tried different XML files, TextBlock instead of a TextBox and so on.
Suggestions and help are much appreciated. Thanks!
Edit:
With Philip Campbell's suggestion the content of the XML file is now correctly parsed into the TextBox. How do I get the TextBox now to show the "raw" file with its tags?
Upvotes: 0
Views: 1208
Reputation: 126
As Default suggests, if you look at the output window you'll see what the error is:
XML binding failed. Cannot obtain result node collection because of bad source node or bad Path...
Which means that your XPath is invalid. I don't know what format your XML is in, or what elements you're trying to read, but changing the XPath to "*" should give you a good starting point, ie:
{Binding Source={StaticResource test}, XPath=*}
Upvotes: 1