Maura Monville

Maura Monville

  • 1.7k
  • 70
  • 6.2k

Do I really need INotifyPropertyChanged?

Mar 8 2022 2:13 PM

I suspect that INotifyPropertyChanged is overkill for what I would like to achieve.
I need:

  • to display a list of strings in a ListBox (the 5th column in the attached picture that is not working yet)
  • to allow the user to edit each ListBox Item and set the status of the contained string (Accepted/Rejected) through the associated CheckBox
  • when the button "Confirm" is clicked, to get access to the ListBox Item strings and the associated Checkbox to save to a database the strings that have "Accepted" status

The ListBox (5th column) is defined as follows:

<ListBox x:Name="AutoStrucNames" Grid.Row="5" Grid.Column="100" Height="600" Margin="80,20,0,40" 
         Width="160"  SelectionMode="Single"  HorizontalAlignment="Left"  Grid.ColumnSpan="10" 
         Background="PowderBlue" 
         DataContext="{Binding ElementName=main}" ItemsSource="{Binding AutoNames}" >
         <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                    <CheckBox x:Name="CheckAccepted" Margin="3" VerticalAlignment="Center" 
                              IsChecked="{Binding IsChecked, Mode=TwoWay}" />
                    <TextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged, 
                            Mode=TwoWay }"/>
                    </StackPanel>
                    </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        

Questions:

  1. Do I need InotiftPropertyChanged to read the edited strings displayed by the ListBox when the Button "Confirm" is clicked??

  2. Do I need to define the set of strings as a List<string> or as an "ObservableCollection<string>"??

Thank you in advance

 

 



Answers (2)