I have a collection of Patients which I set in my ComboBox, whenever I ran and test the form, it seems fine, but whenever I update a record or add another one (from another form), the ComboBox doesn't get updated. I can do a remedy to this by using the code behind and IContent interface but I like to reduce the use of code behind as much as possible. Can you pinpoint to me what markup or code that is lacking?
Here is my Grid Markup (I omitted the RowDefinitions and ColumnDefinitions)
<UserControl.Resources> <common:ImageSourceConverter x:Key="ToImageSourceConverter" /> <businessLogic:PatientMgr x:Key="PatientsViewModel" /> <ObjectDataProvider x:Key="ItemsSource" ObjectInstance="{StaticResource PatientsViewModel}" /> </UserControl.Resources> <Grid x:Name="DetailsGrid" DataContext="{StaticResource ItemsSource}"> <Border Grid.Row="1" Grid.RowSpan="8" Grid.Column="0" Grid.ColumnSpan="2" BorderBrush="Turquoise" BorderThickness="2"> <Image x:Name="InsideButtonImage" VerticalAlignment="Center" HorizontalAlignment="Center" StretchDirection="Both" Stretch="Uniform" Source="{Binding ElementName=FullNameComboBox, Path=SelectedItem.PictureId, Converter={StaticResource ToImageSourceConverter}, UpdateSourceTrigger=PropertyChanged}" /> </Border> <TextBox x:Name="IdTextBox" Text="{Binding ElementName=FullNameComboBox, Path=SelectedItem.Id, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="1" Visibility="Collapsed"/> <ComboBox x:Name="FullNameComboBox" Grid.Row="10" Grid.Column="1" IsEditable="True" ItemsSource="{Binding Path=ComboBoxItemsCollection, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath = "FullName" SelectedIndex="0" SelectionChanged="FullNameComboBox_OnSelectionChanged" /> <TextBox x:Name="GenderTextBox" Text="{Binding ElementName=FullNameComboBox, Path=SelectedItem.GenderName, UpdateSourceTrigger=PropertyChanged}" Grid.Row="11" Grid.Column="1" IsReadOnly="True" IsReadOnlyCaretVisible="True"/> </Grid> Here is my BusinessLogicLayer
public class PatientMgr :INotifyPropertyChanged { #region Fields private readonly PatientDb _db; private Patient _entity; private List<Patient> _entityList; private ObservableCollection<Patient> _comboBoxItemsCollection; private Patient _selectedItem; #endregion #region Properties public Patient Entity { get { return _entity; } set { if (Equals(value, _entity)) return; _entity = value; OnPropertyChanged(); } } public List<Patient> EntityList { get { return _entityList; } set { if (Equals(value, _entityList)) return; _entityList = value; OnPropertyChanged(); } } public ObservableCollection<Patient> ComboBoxItemsCollection { get { return _comboBoxItemsCollection; } set { if (Equals(value, _comboBoxItemsCollection)) return; _comboBoxItemsCollection = value; OnPropertyChanged(); } } public Patient SelectedItem { get { return _selectedItem; } set { if (Equals(value, _selectedItem)) return; _selectedItem = value; OnPropertyChanged(); } } #endregion #region Constructor public PatientMgr() { _db = new PatientDb(); Entity = new Patient(); EntityList = new List<Patient>(); Parameters = new Patient(); ComboBoxItemsCollection = new ObservableCollection<Patient>(_db.RetrieveMany(Entity)); SelectedItem = ComboBoxItemsCollection[0]; } #endregion public List<Patient> RetrieveMany(Patient parameters) { return _db.RetrieveMany(parameters); } public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { var handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } }