tags:

views:

6

answers:

0

Hi experts,

I have a listbox whose itemssource is binded to some list, as follows,

<ListBox Name="li" ItemsSource="{Binding List1}" Grid.Column="1"/>

I handled the selection changed event of ListBox. On the selection changed event I refered the Parent object of the selected item(ie ListBox) using "selected item.parent as ListBox". But it throws null refernce exception. I just want the reason why it is throwing exception.

void li_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        MessageBox.Show((li.SelectedItem as ListBoxItem).Parent.ToString());
    }

Throwing exception in the above line. If i add the items by using li.items.Add() property the same line not throwing any exception.

Can any one explain me the reason of that exception.

Regards, Jawahar