Thursday, October 15, 2009

Clearing Selection on a bound ListBox in SilverLight 2

Spent way too much time trying to figure out how to unselect an item from a Listbox that had it's ItemsSource bound to a collection. Finally figured out that simply removing the binding and adding it back in with a forced layout update would do the trick.

ListBox lb = sender as ListBox;
var test = lb.ItemsSource;
lb.ItemsSource = null;
lb.ItemsSource = test;
lb.UpdateLayout();

No comments: