An Adorner that displays a watermark on a TextBox or ComboBox control.
Inheritance: System.Windows.Documents.Adorner
コード例 #1
0
        /// <summary>
        /// Updates the <see cref="WatermarkAdorner"/> on the <see cref="Control"/>.
        /// </summary>
        /// <param name="control">A <see cref="Control"/>.</param>
        private static void UpdateWatermark(Control control)
        {
            object hint  = GetHint(control);
            Brush  brush = GetHintBrush(control);

            if (!control.IsKeyboardFocused && !HasActualValue(control) && hint != null && brush != null)
            {
                WatermarkAdorner watermarkAdorner = GetWatermarkAdorner(control);

                if (watermarkAdorner == null)
                {
                    AddWatermarkAdorner(control, hint, brush);
                }
                else
                {
                    watermarkAdorner.Hint  = hint;
                    watermarkAdorner.Brush = brush;
                    UpdateAdornerLayer(control);
                }
            }
            else
            {
                RemoveWatermarkAdorner(control);
            }
        }
コード例 #2
0
ファイル: Watermark.cs プロジェクト: YisenYu/Hourglass
        /// <summary>
        /// Updates the <see cref="WatermarkAdorner"/> on the <see cref="Control"/>.
        /// </summary>
        /// <param name="control">A <see cref="Control"/>.</param>
        private static void UpdateWatermark(Control control)
        {
            if (!control.IsKeyboardFocused && !HasActualValue(control))
            {
                WatermarkAdorner watermarkAdorner = GetWatermarkAdorner(control);
                object           hint             = GetHint(control);

                if (watermarkAdorner == null)
                {
                    AddWatermarkAdorner(control, hint);
                }
                else if (!object.Equals(watermarkAdorner.Hint, hint))
                {
                    watermarkAdorner.Hint = hint;
                }
            }
            else
            {
                RemoveWatermarkAdorner(control);
            }
        }