你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 刪除toolkit:listpicker綁定的最後一個元素問題

刪除toolkit:listpicker綁定的最後一個元素問題

編輯:IOS開發綜合

刪除toolkit:listpicker綁定的最後一個元素會拋出SelectedItem must always be set to a valid value這個異常。

目測是這段代碼的問題:

 
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 should 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
        }
有興趣的動手改一改


作者:wingyiu
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved