I'm trying to bind XML data to DataView. I'm following this guide however even though I can see the result under Visual Studio 2013, I cannot see the result when I run the program. I tried adding Movies.xml to Resources and adding it to project directory. Currently it resides under project root path. While I was writing this post, for a while I saw the result while project is running, however after clean build it disappeared again.
Movies.XML:
<?xml version="1.0" encoding="utf-8" ?>
<Movies xmlns="">
<Movie Name="Seven Samurai" Id="101" Director="Akira Kurosawa" />
<Movie Name="Happy Together" Id="102" Director="Wong Kar Wai"/>
<Movie Name="Shoot The Piano Player" Id="103" Director="Francois Truffaut"/>
<Movie Name="Roshomon" Id="104" Director="Akira Kurosawa" />
<Movie Name="Dead Man" Id="105" Director="Jim Jarmusch"/>
<Movie Name="Children of Heaven" Id="106" Director="Majid Majidi"/>
</Movies>
XAML:
<Window x:Class="DataGridXML.MainWindow"
xmlns="http://ift.tt/o66D3f"
xmlns:x="http://ift.tt/mPTqtT"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="MovieData" Source="Movies.xml" XPath="/Movies/Movie"/>
</Grid.Resources>
<DataGrid x:Name="dgridEmp" DataContext="{StaticResource MovieData}" ItemsSource="{Binding XPath=/Movies/Movie}"
AutoGenerateColumns="False" Margin="52,89,31,50">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" />
<DataGridTextColumn Header="Title" Binding="{Binding XPath=@Director}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Visual Studio Preview:
Project run-time:
My final goal is to bind such XML dynamically, so that user will choose which XML to parse. Then user can change the content and save.
No comments:
Post a Comment