Hopefully I can make this clear. I have a DataGrid
<DataGrid Grid.Row="6" Grid.Column="1"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
ItemsSource="{Binding projectEntriesForEmployee}">
bound to an
public ObservableCollection<ProjectEntry> projectEntriesForEmployee {
get { return (ObservableCollection<ProjectEntry>)GetValue(projectEntriesForEmployeeProperty); }
set { SetValue(projectEntriesForEmployeeProperty, value); }
}
public DependencyProperty projectEntriesForEmployeeProperty = DependencyProperty.Register("projectEntriesForEmployee", typeof(ObservableCollection<ProjectEntry>), typeof(MainWindowVC));
If I set projectEntriesForEmployee before I load my UserControl (which I did to debug), my rows show properly in the DataGrid. If however, projectEntriesForEmployee is null when the UserControl loads, when I set projectEntriesForEmployee to a valid ObservableCollection with items in the list (based on an event), no rows show on the DataGrid. What could be going on?
Edit:
I’ve tried
CollectionViewSource.GetDefaultView(projectEntriesForEmployee).Refresh();
but no joy.
Sorry everyone. I’ve answered my own question, as it turns out that the problem was the Dependency Property Owner Type. I had it as MainWindowVC. It should have been TimeEntryVC. As soon as I changed that, I commented out the resetting the ItemsSource in the Controller class, and everything worked as it should. So @Tim, you’re right that the Binding system takes care of things; I just told it to look for the property in the wrong class. Thanks all regardless, as I understand better what’s going on behind the scenes now than I did before.