Delete toolkit: the last element bound to listpicker will throw the SelectedItem must always be set to a valid value exception.
Visual testing is a problem with this Code:
01
Private static void OnSelectedItemChanged (DependencyObject o, DependencyPropertyChangedEventArgs e)
02
{
03
(ListPicker) o). OnSelectedItemChanged (e. OldValue, e. NewValue );
04
}
05
06
[SuppressMessage ("Microsoft. Naming", "CA2204: Literals shocould be spelled correctly", MessageId = "SelectedItem", Justification = "Property name.")]
07
Private void OnSelectedItemChanged (object oldValue, object newValue)
08
{
09
If (newValue! = Null & (null = Items | Items. Count = 0 ))
10
{
11
If (null = Template)
12
{
13
// Can't set the value now; remember it for later
14
_ DeferredSelectedItem = newValue;
15
Return;
16
}
17
Else
18
{
19
Throw new InvalidOperationException (Properties. Resources. InvalidSelectedItem );
20
}
21
}
22
23
// Validate new value
24
Int newValueIndex = (null! = NewValue )? Items. IndexOf (newValue):-1;
25
26
If (-1 = newValueIndex) & (0 <Items. Count ))
27
{
28
Throw new InvalidOperationException (Properties. Resources. InvalidSelectedItem );
29
}
30
31
// Synchronize SelectedIndex property
32
If (! _ UpdatingSelection)
33
{
34
_ UpdatingSelection = true;
35
SelectedIndex = newValueIndex;
36
_ UpdatingSelection = false;
37
}
38
39
// Switch to Normal mode or size for current item
40
If (ListPickerMode. Normal! = ListPickerMode)
41
{
42
ListPickerMode = ListPickerMode. Normal;
43
}
44
Else
45
{
46
SizeForAppropriateView (false );
47
}
48
49
// Fire SelectionChanged event
50
Var handler = SelectionChanged;
51
If (null! = Handler)
52
{
53
IList removedItems = (null = oldValue )? New object [0]: new object [] {oldValue };
54
IList addedItems = (null = newValue )? New object [0]: new object [] {newValue };
55
Handler (this, new SelectionChangedEventArgs (removedItems, addedItems ));
56
}
57
}
Change it if you are interested
Author: wingyiu