I have a DataGrid inside my WPF application and I would like it to contain values from my XML file. The DataGrid is shown below:
<TabItem Header="Datacopy">
<Grid>
<DataGrid x:Name="GrdDatacopy" HorizontalAlignment="Left" Margin="7,7,0,0" VerticalAlignment="Top" Height="320" Width="640">
<DataGrid.Columns>
<DataGridTextColumn DisplayMemberBinding="{Binding Path = Source}" Header="Bron:"></DataGridTextColumn>
<DataGridTextColumn DisplayMemberBinding="{Binding Path = Destination}" Header="Doel:"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</TabItem>
My XML:
<DataCopy Dir="H:\O365-Source">
<Row Source="C:\Temp" Destination="Temp" />
<Row Source="C:\Downloads" Destination="Downloads" />
<Row Source="C:\Muziek" Destination="Muziek" />
</DataCopy>
I can create a object for the datagrid
$DatacopySet = @{}
$XmlOffice365.Office365.Datacopy.Row | ForEach {
$DatacopySet.add($_.Source))
$DatacopySet.add($_.Destination))
}
$DatacopySet | ForEach-Object { .................... }
But when I paste in the secion my whole app crashes, it should be something with the bindings.
How can I get my XML keys in the datagrid and be able to edit these.
I've found some samples but I couldn't get this to work...
PS1 script http://poshcode.org/2259
XAML code: http://poshcode.org/2260
Hope that someone can help, or is there a other way to easaly edit and add values in this sort of setting?
Regards, Paul
You can display your xml data in the following way
Note:
-XmlDataProvider can be used with different Sources, including URIs
-Note the empty xmlns="" in the xml-snippet. You easily run into namespace issues otherwise.
-Editing the document is also possible in case the XmlDataProvider's Source is a variable in memory. You must call XmlDocument.Save() manually.
Hope this helps a bit, regards Snowball