Click here to Skip to main content
15,912,207 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Bind To Static Property Pin
Kevin Marois13-Jan-17 8:25
professionalKevin Marois13-Jan-17 8:25 
GeneralRe: Bind To Static Property Pin
Richard Deeming13-Jan-17 8:29
mveRichard Deeming13-Jan-17 8:29 
GeneralRe: Bind To Static Property Pin
Kevin Marois13-Jan-17 8:31
professionalKevin Marois13-Jan-17 8:31 
QuestionWPF/MVVM - How To Make A Chess Board Pin
Kevin Marois20-Dec-16 6:13
professionalKevin Marois20-Dec-16 6:13 
AnswerRe: WPF/MVVM - How To Make A Chess Board Pin
Meshack Musundi26-Dec-16 19:26
professionalMeshack Musundi26-Dec-16 19:26 
QuestionMetroTabItem View Going out of Scope Pin
JPKI13-Dec-16 12:59
JPKI13-Dec-16 12:59 
AnswerRe: MetroTabItem View Going out of Scope Pin
Pete O'Hanlon13-Dec-16 20:50
mvePete O'Hanlon13-Dec-16 20:50 
GeneralRe: MetroTabItem View Going out of Scope Pin
JPKI13-Dec-16 22:14
JPKI13-Dec-16 22:14 
GeneralRe: MetroTabItem View Going out of Scope Pin
JPKI15-Dec-16 8:33
JPKI15-Dec-16 8:33 
QuestionUserControl Pin
Kevin Marois5-Dec-16 11:02
professionalKevin Marois5-Dec-16 11:02 
AnswerRe: UserControl Pin
Jon McKee5-Dec-16 11:12
professionalJon McKee5-Dec-16 11:12 
GeneralRe: UserControl Pin
Kevin Marois5-Dec-16 11:22
professionalKevin Marois5-Dec-16 11:22 
GeneralRe: UserControl Pin
Jon McKee5-Dec-16 11:40
professionalJon McKee5-Dec-16 11:40 
GeneralRe: UserControl Pin
Kevin Marois5-Dec-16 11:46
professionalKevin Marois5-Dec-16 11:46 
GeneralRe: UserControl Pin
Jon McKee5-Dec-16 11:56
professionalJon McKee5-Dec-16 11:56 
AnswerRe: UserControl Pin
Gerry Schmitz5-Dec-16 11:29
mveGerry Schmitz5-Dec-16 11:29 
GeneralRe: UserControl Pin
Meshack Musundi5-Dec-16 22:23
professionalMeshack Musundi5-Dec-16 22:23 
GeneralRe: UserControl Pin
Kevin Marois6-Dec-16 4:49
professionalKevin Marois6-Dec-16 4:49 
GeneralRe: UserControl Pin
Meshack Musundi6-Dec-16 5:04
professionalMeshack Musundi6-Dec-16 5:04 
AnswerRe: UserControl Pin
Richard Deeming6-Dec-16 2:10
mveRichard Deeming6-Dec-16 2:10 
GeneralRe: UserControl Pin
Kevin Marois6-Dec-16 4:47
professionalKevin Marois6-Dec-16 4:47 
QuestionC# WPF listbox binding to selected item does not update my property Pin
Member 128805954-Dec-16 5:54
Member 128805954-Dec-16 5:54 
AnswerRe: C# WPF listbox binding to selected item does not update my property Pin
Richard Deeming5-Dec-16 1:58
mveRichard Deeming5-Dec-16 1:58 
You're replacing the entire conversation list, so you need to make it a property, and call RaisePropertyChanged when you replace it.

You'll also need to call PopulateConversationList when the selected contact changes.

You can simplify the calls to RaisePropertyChanged by using the CallerMemberName attribute[^] on the parameter. You should also store the event handler delegate in a local variable before testing and calling it, since other threads might modify it between the null test and the invocation.
C#
public event PropertyChangedEventHandler PropertyChanged;

protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
    var handler = PropertyChanged;
    if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}

C#
public class MainViewModel : ViewModelBase
{
    private Contact selectedContact;
    private ObservableCollection<Contact> contactList;
    private ObservableCollection<Conversation> conversationList;
    
    public MainViewModel()
    {
        contactList = new ObservableCollection<Contact>(cbdc.Contacts);
        SelectedContact = contactList.FirstOrDefault();
    }
    
    public ObservableCollection<Contact> ContactList
    {
        get { return contactList; }
    }
    
    public Contact SelectedContact
    {
        get
        {
            return selectedContact;
        }
        set
        {
            if (selectedContact != value)
            {
                selectedContact = value;
                RaisePropertyChanged();
                PopulateConversationList();
            }
        }
    }
    
    public ObservableCollection<Conversation> ConversationList
    {
        get
        {
            return conversationList;
        }
        private set
        {
            if (conversationList != value)
            {
                conversationList = value;
                RaisePropertyChanged();
            }
        }
    }
    
    private void PopulateConversationList()
    {
        if (selectedContact == null)
        {
            ConversationList = null;
        }
        else
        {
            var conversations = from c in cbdc.Conversations
                                where c.ContactID == SelectedContact.Id
                                select c;
            
            ConversationList = new ObservableCollection<Conversation>(conversations);
        }
    }
}




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


GeneralRe: C# WPF listbox binding to selected item does not update my property Pin
Member 128805955-Dec-16 9:08
Member 128805955-Dec-16 9:08 
GeneralRe: C# WPF listbox binding to selected item does not update my property Pin
Jon McKee5-Dec-16 10:59
professionalJon McKee5-Dec-16 10:59 

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.