Please let me know if there's something wrong with my approach. I have a WPF window which contains a datagrid. This is for the users to input a list of object IDs for the program to process.
I am binding the ItemsSource of the DataGrid to an ObservableCollection, where MyObject is a class with a single string property - ObjectId.
I have an event for when collection is changed:
void TasksList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
ProgressBarMax = TasksList.Count;
TaskCountLabel = string.Format("{0} tasks to modify", TasksList.Count);
}
I would also like to validate the data on input - the user might provide an incorrect Id, in which case I don't want to add it to the collection. However, when I access the e.NewItems[0] object, its ObjectId property is still null, so I cannot validate.
What is wrong with my approach?
Adding datagrid XAML as per comments:
<DataGrid Margin="5,0,5,10"
ColumnWidth="*"
ItemsSource="{Binding ElementName=ThisUc,
Path=TasksList,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
Style="{x:Null}"
CanUserAddRows="True" CanUserPasteToNewRows="True"
x:Name="TasksDataGrid"
CanUserDeleteRows="True"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
SelectionUnit="Cell" />
ICommand? - Mike Eason