Пример #1
0
        /// <summary>
        /// Handle the ItemsSource changing.
        /// </summary>
        /// <param name="sender">The combo box.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private static void OnItemsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            PersistentComboBox box = sender as PersistentComboBox;

            box.SelectedValue = box.selectedValue;

            if (eventArgs.OldValue is INotifyCollectionChanged)
            {
                (eventArgs.OldValue as INotifyCollectionChanged).CollectionChanged -= (sender as PersistentComboBox).OnItemsChanged;

                if (eventArgs.OldValue is IDataBoundList)
                {
                    (eventArgs.OldValue as IDataBoundList).CollectionChanging -= (sender as PersistentComboBox).OnItemsChanging;
                }
            }
            if (eventArgs.NewValue is INotifyCollectionChanged)
            {
                (eventArgs.NewValue as INotifyCollectionChanged).CollectionChanged += (sender as PersistentComboBox).OnItemsChanged;

                if (eventArgs.NewValue is IDataBoundList)
                {
                    (eventArgs.NewValue as IDataBoundList).CollectionChanging -= (sender as PersistentComboBox).OnItemsChanging;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Do any setup before the ItemsSource changes.
        /// </summary>
        /// <param name="sender">The combo box.</param>
        /// <param name="baseValue">The proposed value of ItemsSource.</param>
        /// <returns></returns>
        private static object BeforeItemsSourceChanged(DependencyObject sender, object baseValue)
        {
            PersistentComboBox box = sender as PersistentComboBox;

            box.selectedValue = box.SelectedValue;

            return(baseValue);
        }
Пример #3
0
        /// <summary>
        /// Handle a change in the selected value.
        /// </summary>
        /// <param name="sender">The combo box.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private static void OnSelectedValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            PersistentComboBox box = sender as PersistentComboBox;

            box.RaiseEvent(new RoutedEventArgs(PersistentComboBox.PersistentSelectedValueChangedEvent, box));

            if (box.selectedValue == null)
            {
                box.selectedValue = eventArgs.NewValue;
            }
        }