Esempio n. 1
0
        /// <summary>
        /// This is called when the watermark color is changed
        /// </summary>
        /// <param name="dpo"></param>
        /// <param name="e"></param>
        private static void OnColorChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            WatermarkTextBehavior wtb = (WatermarkTextBehavior)dpo;

            if (wtb.AssociatedObject != null)
            {
                wtb.OnChangeWatermarkColor();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This is called when the watermark visibility changes.
        /// </summary>
        /// <param name="dpo"></param>
        /// <param name="e"></param>
        private static void OnChangeWatermarkVisibility(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            WatermarkTextBehavior wtb = (WatermarkTextBehavior)dpo;

            if ((bool)e.NewValue == true)
            {
                if (!wtb.OnSetWatermarkText())
                {
                    wtb.IsWatermarkVisible = false;
                }
            }
            else
            {
                wtb.OnRemoveWatermarkText();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This is called when the watermark text is changed on either a WatermarkTextboxBehavior
        /// OR on a TextBox directly to attach/detach the behavior.
        /// </summary>
        /// <param name="dpo"></param>
        /// <param name="e"></param>
        private static void OnTextChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            WatermarkTextBehavior wtb = dpo as WatermarkTextBehavior;

            if (wtb != null)
            {
                if (wtb.AssociatedObject != null)
                {
                    wtb.IsWatermarkVisible = true;
                }
            }
            // Attach/Detach request
            else
            {
                TextBox tb = dpo as TextBox;
                if (tb != null)
                {
                    string text         = (e.NewValue ?? "").ToString();
                    var    behaviors    = Interaction.GetBehaviors(tb);
                    var    thisBehavior =
                        behaviors.FirstOrDefault(b => b is WatermarkTextBehavior) as WatermarkTextBehavior;

                    if (string.IsNullOrWhiteSpace(text))
                    {
                        if (thisBehavior != null)
                        {
                            behaviors.Remove(thisBehavior);
                        }
                    }
                    else
                    {
                        if (thisBehavior == null)
                        {
                            thisBehavior = new WatermarkTextBehavior()
                            {
                                WatermarkText = text
                            };
                            behaviors.Add(thisBehavior);
                        }
                        else
                        {
                            thisBehavior.WatermarkText = text;
                        }
                    }
                }
            }
        }