Exemplo n.º 1
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double        fontSize;
            Typeface      typeFace;
            TextAlignment alignment;
            FlowDirection flowDirection;
            double        padding;

            if (AdornedPasswordBox != null)
            {
                alignment     = ConvertAlignment(AdornedPasswordBox.HorizontalContentAlignment);
                flowDirection = AdornedPasswordBox.FlowDirection;
                fontSize      = AdornedPasswordBox.FontSize;
                typeFace      = AdornedPasswordBox.FontFamily.GetTypefaces().FirstOrDefault();
                padding       = 6;
            }
            else
            {
                alignment     = AdornedTextBox.ReadLocalValue(TextBox.TextAlignmentProperty) != DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment(AdornedTextBox.HorizontalContentAlignment);
                flowDirection = AdornedTextBox.FlowDirection;
                fontSize      = AdornedTextBox.FontSize;
                typeFace      = AdornedTextBox.FontFamily.GetTypefaces().FirstOrDefault();
                padding       = 6;
            }
            var text = new System.Windows.Media.FormattedText(PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray)
            {
                TextAlignment = alignment
            };

            drawingContext.DrawText(text, new System.Windows.Point(padding, (RenderSize.Height - text.Height) / 2));
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double        fontSize;
            Typeface      typeFace;
            TextAlignment alignment;
            FlowDirection flowDirection;
            bool          multiline = false;
            double        ypos = 3, xpos = 6;

            if (AdornedPasswordBox != null)
            {
                alignment     = ConvertAlignment(AdornedPasswordBox.HorizontalContentAlignment);
                flowDirection = AdornedPasswordBox.FlowDirection;
                fontSize      = AdornedPasswordBox.FontSize;
                typeFace      = AdornedPasswordBox.FontFamily.GetTypefaces().FirstOrDefault();
            }
            else if (AdornedTextBox != null)
            {
                multiline     = AdornedTextBox.AcceptsReturn;
                alignment     = AdornedTextBox.ReadLocalValue(TextBox.TextAlignmentProperty) != DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment(AdornedTextBox.HorizontalContentAlignment);
                flowDirection = AdornedTextBox.FlowDirection;
                fontSize      = AdornedTextBox.FontSize;
                typeFace      = AdornedTextBox.FontFamily.GetTypefaces().FirstOrDefault();
            }
            else
            {
                alignment     = ConvertAlignment(AdornedComboBox.HorizontalContentAlignment);
                flowDirection = AdornedComboBox.FlowDirection;
                fontSize      = AdornedComboBox.FontSize;
                typeFace      = AdornedComboBox.FontFamily.GetTypefaces().FirstOrDefault();
            }
            var text = new System.Windows.Media.FormattedText(PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray);


            if (!multiline)
            {
                ypos = (RenderSize.Height - text.Height) / 2;
            }

            switch (alignment)
            {
            case TextAlignment.Center:
                xpos = (RenderSize.Width - text.Width) * 0.5;
                break;

            case TextAlignment.Right:
                xpos = (RenderSize.Width - text.Width) - 6;
                break;
            }

            drawingContext.DrawText(text, new System.Windows.Point(xpos, ypos));
        }