Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataGrid Bound to XML not Refreshing

$
0
0

I have a DataGrid bound to an XmlDataSource.  Here is my (partial) XML:

<Settings xmlns=""><Profiles xmlns="" ActiveProfile="0"><Profile Id="0" Desc="- none -" Port="0" Baud="0" DataBits="0" Parity="0" StopBits="0" CharDelay="0" ReadTimeout="0" ProcInterval="0" SetInterval="0" DecInterval="0" ChartInterval="0" SaveInterval="0"><PIDs><PID Address="1" SetPoint="one" ProcVal="one" /><PID Address="2" SetPoint="two" ProcVal="two" /><PID Address="3" SetPoint="three" ProcVal="three" /></PIDs></Profile><Profile Id="1" Desc="Test Profile 1" Port="1" Baud="19200" DataBits="7" Parity="0" StopBits="3" CharDelay="1" ReadTimeout="100" ProcInterval="100" SetInterval="0" DecInterval="0" ChartInterval="0" SaveInterval="0"><PIDs><PID Address="" Name="" /></PIDs>
</Profile>
...
...
</Profiles>

I have a ComboBox bound to the Profiles, so when I select a new item, it updates the new Profile's Id attribute value into the parent node's ActiveProfile attribute.

Here is XmlDataProvider XAML:

<Window.Resources><XmlDataProvider x:Name="PIDData" x:Key="PIDData" Source ="Settings.xml" XPath="Settings/Profiles"/>

Here is DataGrid XAML:

<DataGrid AutoGenerateColumns="False" Height="201" HorizontalAlignment="Left" Margin="233,137,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="444"
          ItemsSource="{Binding Source={StaticResource PIDData}, XPath=Profile[@Id\=../@ActiveProfile]/PIDs/PID}"><DataGrid.Columns><DataGridTextColumn Header="Address" Binding="{Binding XPath=@Address}"/><DataGridTextColumn Header="Set Point" Binding="{Binding XPath=@SetPoint}"/><DataGridTextColumn Header="Proc Val" Binding="{Binding XPath=@ProcVal}"/></DataGrid.Columns></DataGrid>

The XPath in the ItemsSource, which refers to the parent's ActiveProfile seems to work fine for my other controls which use the same type of binding.

When I select another item in the Profiles ComboBox, everything works as expected, except the DataGrid does not refresh.  If I have a different list of data items in a different XML node, it does not display, only the original list of items in the DataGrid remains.

All of my binding is done via XAML, none in code-behind.  Is there a way to cause the DataContext to refresh when I select a different ComboBox item?  I don't mind doing that in code-behind if that's what it takes (although it seems like it should work just from XAML).

Thanks...


Ron Mittelman


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>