private void OnSelectedIndexChanged(int oldValue, int newValue)
{
// Validate new value
if ((Items.Count <= newValue) ||
((0 < Items.Count) && (newValue < 0)) ||
((0 == Items.Count) && (newValue != -1)))
{
if ((null == Template) && (0 <= newValue))
{
// Can't set the value now; remember it for later
_deferredSelectedIndex = newValue;
return;
}
}
// Synchronize SelectedItem property
if (!_updatingSelection)
{
_updatingSelection = true;
SelectedItem = (-1 != newValue) ? Items[newValue] : null;
_updatingSelection = false;
}
if (-1 != oldValue)
{
// Toggle container selection
ListPickerItem oldContainer = (ListPickerItem)ItemContainerGenerator.ContainerFromIndex(oldValue);
if (null != oldContainer)
{
oldContainer.IsSelected = false;
}
}
}