Beginner problems: A way to refresh a datagrid bind with a XML file?

Mar 15, 2015 at 10:59 PM
I'm using VS 2013 with PTVS and I want to update my datagrid when I change the XML file. But I'm beginner for python and WPF so I'm getting some trouble, so my XML file is:
    <XmlDataProvider x:Key="XML_Vendas" Source="C:\Users\Felipe\Documents\Visual Studio 2013\Projects\Metal Goat Manager\Metal Goat Manager\Vendas.xml" IsAsynchronous="False"/>
And my datagrid:
<DataGrid x:Name="datagridvendas" Opacity="0" AutoGenerateColumns="False" Height="auto" Width="auto" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource XML_Vendas},XPath=Vendas/*,Mode=TwoWay}">
                <DataGridTextColumn Header="Id" Binding="{Binding XPath=@Venda_Id}"/>
                <DataGridTextColumn Header="Data" Binding="{Binding XPath=@Compra_Data}"/>
                <DataGridTextColumn Header="Produto" Binding="{Binding XPath=@Prod_Desc}"/>
                <DataGridTextColumn Header="Pag" Binding="{Binding XPath=@Pag_Status}"/>
                <DataGridTextColumn Header="Entrega" Binding="{Binding XPath=@Met_Entrega}"/>
                <DataGridTextColumn Header="Nick" Binding="{Binding XPath=@Buyer_Nick}"/>
                <DataGridTextColumn Header="Nome" Binding="{Binding XPath=@Buyer_Name}"/>
                <DataGridTextColumn Header="Sobrenome" Binding="{Binding XPath=@Buyer_LastName}"/>
                <DataGridTextColumn Header="CPF" Binding="{Binding XPath=@Buyer_Cpf}"/>
                <DataGridTextColumn Header="Email" Binding="{Binding XPath=@Buyer_Email}"/>
                <DataGridTextColumn Header="Avaliacao Recebida" Binding="{Binding XPath=@Buyer_Feed}"/>
                <DataGridTextColumn Header="Avaliacao Enviada" Binding="{Binding XPath=@Seller_Feed}"/>
I've already tried datagrid.Items.Refresh(), but nothing happen.
Mar 15, 2015 at 11:07 PM
Calling Refresh on the grid simply causes it to reload the data from the data source. But the data source is the document that is loaded in memory; it's not automatically synced to the file on disk.

To do a one-off refresh, you need to call Refresh on the XmlDataProvider. If you want to refresh it every time the file changes on disk, you'll need to detect those changes yourself - look at FileSystemWatcher for that.

You might want to post questions such as these to StackOverflow rather than here - this is a discussion board specifically about PTVS, and your questions are generic IronPython/WPF ones. You'll get significantly more people looking at them there.
Marked as answer by pantalipe on 3/24/2015 at 4:35 PM
Mar 16, 2015 at 12:13 AM
Ok, thanks for the answer! I will take a look at these points.

I have tried the stackOverflow and CodeProject yesterday, but answers for IronPython/WPF are very rare i dont know why.

Here in less than 10 minutes I got your answer, and now I can continue with my research and my programming.