0

I have a simple datagrid bound to a ObservableCollection. It should display only one column.

The XAML looks like this:

 <DataGrid  IsReadOnly="True" ItemsSource="{Binding InputList, UpdateSourceTrigger=PropertyChanged}" 
                                       HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoGenerateColumns="False">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Parameter Name"  Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged}">
                                    </DataGridTextColumn>
                                </DataGrid.Columns>
                            </DataGrid>

In my ViewModel the ObservableCollection looks like this:

 public ObservableCollection<InputParameter> InputList { get; set; }

InputParameter contains a string property "Name" which I want to display. If I add some parameters in the contructor like this:

  InputParameter parameter = new InputParameter("test1");
  InputList.Add(parameter);

the item is displayed, but if I do the same thing in a method that is called on some event and the list is not updated. What am I missing here?

This is the code that should add items to the collection on the PropertyChanged event, but the display is not updated:

 Manager.PropertyChanged += (obj, e) =>
        {
            if(e.PropertyName == "Inputs")
            {
                foreach (InputParameter param in Manager.Inputs)
                {
                    parameter = new InputParameter("test2");
                    InputList.Add(parameter);
                  //  InputList.Add(param);
                }

            };

        };
mobearette
  • 377
  • 10
  • 26

0 Answers0