Esempio n. 1
0
        /// <summary>
        ///     Handles changes to the Watermark property.
        /// </summary>
        /// <param name="d"><see cref="DependencyObject" /> that fired the event</param>
        /// <param name="e">A <see cref="DependencyPropertyChangedEventArgs" /> that contains the event data.</param>
        private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Control control = (Control)d;

            control.Loaded += Control_Loaded;

            ComboBox            comboBox            = d as ComboBox;
            TextBox             textBox             = d as TextBox;
            AutoCompleteTextBox autoCompleteTextBox = d as AutoCompleteTextBox;

            if (comboBox != null || textBox != null || autoCompleteTextBox != null)
            {
                control.GotKeyboardFocus  += Control_GotKeyboardFocus;
                control.LostKeyboardFocus += Control_Loaded;

                if (textBox != null)
                {
                    textBox.TextChanged += TextBox_TextChanged;
                }
                else if (autoCompleteTextBox != null)
                {
                    autoCompleteTextBox.TextChanged += TextBox_TextChanged;
                }
            }

            ItemsControl i = d as ItemsControl;

            if (i != null && comboBox == null)
            {
                // for Items property
                i.ItemContainerGenerator.ItemsChanged += ItemsChanged;
                ItemsControls.Add(i.ItemContainerGenerator, i);

                // for ItemsSource property
                DependencyPropertyDescriptor prop = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, i.GetType());
                prop.AddValueChanged(i, ItemsSourceChanged);
            }
        }