Click here to Skip to main content
14,422,213 members

Silverlight / WPF

 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois22-May-17 6:23
professionalKevin Marois22-May-17 6:23 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 7:15
mveGerry Schmitz22-May-17 7:15 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 7:35
mveGerry Schmitz22-May-17 7:35 
GeneralRe: Custom SplitButton Control Styling Pin
Kevin Marois22-May-17 7:50
professionalKevin Marois22-May-17 7:50 
GeneralRe: Custom SplitButton Control Styling Pin
Gerry Schmitz22-May-17 8:07
mveGerry Schmitz22-May-17 8:07 
QuestionTheming Question Pin
Kevin Marois5-May-17 8:29
professionalKevin Marois5-May-17 8:29 
QuestionWPF MVVM ListView Bound to ObservableCollection doesnt update after i make changes Pin
Member 1288059527-Apr-17 8:25
MemberMember 1288059527-Apr-17 8:25 
AnswerRe: WPF MVVM ListView Bound to ObservableCollection doesnt update after i make changes Pin
Richard Deeming27-Apr-17 9:26
communityengineerRichard Deeming27-Apr-17 9:26 
The problem is that the context you're using to make the changes has no connection to the ObservableCollection<T> which holds the current list of readers.

You need some way for the ReaderManagingViewModel to notify the HomeViewModel when something changes.

The standard approach would be to use a mediator service:
MVVM Mediator Pattern[^]
A Mediator Prototype for WPF Apps | Josh Smith on WPF[^]

Alternatively, as a "quick-and-dirty" approach, you could store the HomeViewModel instance passed to the ReaderManagingViewModel constructor, and call public methods on that instance to add, update and delete readers from the list.

Depending on your requirements, you could either have a single method to reload the entire list:
public void LoadReaders()
{
    using (BookDBDataContext rdb = new BookDBDataContext())
    {
        ReadersList = new ObservableCollection<Reader>(rdb.Readers);
    }
}

Or you could have separate methods to add, update and delete the readers:
public void AddReader(Reader readerToAdd)
{
    ReadersList.Add(readerToAdd);
}

public void UpdateReader(Reader readerToUpdate)
{
    var reader = ReadersList.FirstOrDefault(r => r.Id == readerToUpdate.Id);
    if (reader != null)
    {
        reader.FullName = readerToUpdate.FullName;
        reader.SerialNumber = readerToUpdate.SerialNumber;
        reader.IdNumber = readerToUpdate.IdNumber;
        reader.Adress = readerToUpdate.Adress;
        reader.AltContactMethods = readerToUpdate.AltContactMethods;
    }
    else
    {
        ReadersList.Add(readerToUpdate);
    }
}

public void DeleteReader(Reader readerToDelete)
{
    var readerToRemove = ReadersList.FirstOrDefault(r => r.Id == readerToDelete.Id);
    if (readerToRemove != null) ReadersList.Remove(readerToRemove);
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: WPF MVVM ListView Bound to ObservableCollection doesnt update after i make changes Pin
Member 1288059527-Apr-17 10:02
MemberMember 1288059527-Apr-17 10:02 
GeneralRe: WPF MVVM ListView Bound to ObservableCollection doesnt update after i make changes Pin
Member 1288059528-Apr-17 11:12
MemberMember 1288059528-Apr-17 11:12 
QuestionWPF Control Template Documentation Pin
Kevin Marois20-Apr-17 6:16
professionalKevin Marois20-Apr-17 6:16 
AnswerRe: WPF Control Template Documentation Pin
CHill6020-Apr-17 6:21
mveCHill6020-Apr-17 6:21 
GeneralRe: WPF Control Template Documentation Pin
Kevin Marois20-Apr-17 7:12
professionalKevin Marois20-Apr-17 7:12 
GeneralRe: WPF Control Template Documentation Pin
CHill6020-Apr-17 8:23
mveCHill6020-Apr-17 8:23 
GeneralRe: WPF Control Template Documentation Pin
Kevin Marois20-Apr-17 8:24
professionalKevin Marois20-Apr-17 8:24 
AnswerRe: WPF Control Template Documentation Pin
Pete O'Hanlon24-Apr-17 21:31
communityengineerPete O'Hanlon24-Apr-17 21:31 
QuestionComboBox Control Template Problem Pin
Kevin Marois19-Apr-17 13:13
professionalKevin Marois19-Apr-17 13:13 
AnswerRe: ComboBox Control Template Problem Pin
Pete O'Hanlon19-Apr-17 22:42
communityengineerPete O'Hanlon19-Apr-17 22:42 
GeneralRe: ComboBox Control Template Problem Pin
Kevin Marois20-Apr-17 5:38
professionalKevin Marois20-Apr-17 5:38 
QuestionWPF Enum DP - The default value type does not match the type of the property Pin
Kevin Marois18-Apr-17 8:21
professionalKevin Marois18-Apr-17 8:21 
AnswerRe: WPF Enum DP - The default value type does not match the type of the property Pin
Pete O'Hanlon20-Apr-17 0:34
communityengineerPete O'Hanlon20-Apr-17 0:34 
QuestionTimeline Thumb Style Pin
Kevin Marois18-Apr-17 7:19
professionalKevin Marois18-Apr-17 7:19 
QuestionInterpret an Error Pin
Mycroft Holmes28-Mar-17 23:31
MemberMycroft Holmes28-Mar-17 23:31 
AnswerRe: Interpret an Error - Resolved Pin
Mycroft Holmes28-Mar-17 23:51
MemberMycroft Holmes28-Mar-17 23:51 
QuestionBinding Delay Pin
Mycroft Holmes20-Mar-17 18:14
MemberMycroft Holmes20-Mar-17 18:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.