I'm a bit new to the DataGrid control in WPF. I've built a DataGrid into a UserControl, and wrapped that UserControl in a Window. The DataGrid:
<DataGrid x:Name="mDataGrid" RenderTransformOrigin="0.167,-0.077" Margin="-2.572,0,5.428,0" IsReadOnly="True" AlternatingRowBackground="#1EA2A2E2" AutoGenerateColumns="False" Height="389" VerticalAlignment="Top" Grid.ColumnSpan="5">
<DataGrid.Columns>
<DataGridTextColumn Header="Term" Binding="{Binding Term}"/>
<DataGridTextColumn Header="Alternate" Binding="{Binding Alternate}"/>
<DataGridTextColumn Header="Document" Binding="{Binding Document}"/>
<DataGridTextColumn Header="POS" Binding="{Binding POS}"/>
<DataGridTextColumn Header="Meaning" Binding="{Binding Meaning}"/>
</DataGrid.Columns>
</DataGrid>
The C# code that I use to prep and display the control housing it:
ObservableCollection<LexiconEntry> oc = new ObservableCollection<LexiconEntry>();
foreach (KeyValuePair<string,LexiconEntry> kvp in lex.Entries)
{
LexiconEntry le=kvp.Value;
oc.Add(le);
}
mDataGrid.ItemsSource = oc;
Now if I run the app without calling the above routine- meaning that the DataGrid is empty- everything closes properly. If, on the other hand, I call the above routine to link an ItemSource to the DataGrid, the process remains running after I close all the windows. I need to kill it with either the task manager or shift+F5 from within VS. The windows close and I've traced through the Window_Closing and Window_Closed event handlers to verify this, but the process won't shut itself down. I'm not quite sure how to see what's keeping it alive from within the debugger, but the only thing that causes this difference in whether or not the app exits gracefully is populating the DataGrid.
How can I fix this? I've tried setting the DataGrid's ItemSource to null from within the OnClosing event of its parent window, but that hasn't helped.
Thanks!