Exemple #1
0
        private static TextBlock EnsureAdorner(TextBox textBox) {
            var content = GetAdornerContent(textBox);
            if (content != null) {
                return (TextBlock)content;
            } 

            var textBlock = new TextBlock {
                Foreground = (Brush)textBox.FindResource(Brushes.GrayTextBrushKey),
                Margin = new Thickness(2,0,0,0),
                VerticalAlignment = VerticalAlignment.Center,
                Visibility = string.IsNullOrEmpty(textBox.Text) ? Visibility.Visible : Visibility.Collapsed
            };

            textBox.TextChanged += (sender, args) => {
                textBlock.Visibility = string.IsNullOrEmpty(textBox.Text) ? Visibility.Visible : Visibility.Collapsed;
            };

            SetAdornerContent(textBox, textBlock);

            return textBlock;
        }