Delete toolkit: last element bound to listpicker

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.