Thursday, November 28, 2013

WPF - Mutually Exclusive Listboxes and maintain single selection

Problem Statement:

I have two listboxes and i need to maintain single selection across the page within the listboxes.

Solution:

Keep SelectedItem as single and have like below

private Employee selectedItem;
public Employee SelectedItem{
    get
    {
        return selectedItem;
    }
    set
    {
       //For clearing existing selection
        selectedItem = null;
        NotifyPropertyChanged("SelectedItem");

        //For assigning new selection
        selectedItem = value;
        NotifyPropertyChanged("SelectedItem");
    }