Error in WPF? TextBlock inside Adorner displays reverse text when FlowDirection is RightToLeft

I am using adorner to display a watermark inside my textbox. but when I set the FlowDirection of the window to RightToLeft the text inside the adorner (which is the textbox) is reversed !!!

Is this a bug or should I change something?

enter image description here

and here is the complete adorner code:

namespace Hezareh.Modules.Accounting  
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Media;

    internal class WatermarkAdorner : Adorner
        #region Private Fields

        private readonly ContentPresenter contentPresenter;


        #region Constructor

        public WatermarkAdorner(UIElement adornedElement, object watermark) :
            this.IsHitTestVisible = false;
            this.contentPresenter = new ContentPresenter();
            this.contentPresenter.Content = watermark;
            this.contentPresenter.Opacity = 0.5;
            this.contentPresenter.Margin = new Thickness(Control.Margin.Left + Control.Padding.Left, Control.Margin.Top + Control.Padding.Top, 0, 0);
            if (this.Control is ItemsControl && !(this.Control is ComboBox))
                this.contentPresenter.VerticalAlignment = VerticalAlignment.Center;
                this.contentPresenter.HorizontalAlignment = HorizontalAlignment.Center;

            // Hide the control adorner when the adorned element is hidden
            Binding binding = new Binding("IsVisible");
            binding.Source = adornedElement;
            binding.Converter = new BooleanToVisibilityConverter();
            this.SetBinding(VisibilityProperty, binding);


        #region Protected Properties

        protected override int VisualChildrenCount
            get { return 1; }


        #region Private Properties

        private Control Control
            get { return (Control)this.AdornedElement; }


        #region Protected Overrides

        protected override Visual GetVisualChild(int index)
            return this.contentPresenter;

        protected override Size MeasureOverride(Size constraint)
            // Here the secret to getting the adorner to cover the whole control
            return Control.RenderSize;

        protected override Size ArrangeOverride(Size finalSize)
            this.contentPresenter.Arrange(new Rect(finalSize));
            return finalSize;




and i use it:

        <toolkit:AutoCompleteBox Margin="5" Text="" Name="searchCategoriesTextBox">
                <i:EventTrigger EventName="TextChanged">
                    <i:InvokeCommandAction Command="{Binding SearchCommand}"  />
                <TextBlock TextAlignment="Left" Text="Ψ¬Ψ³Ψͺجو" FontFamily="Tahoma" Margin="3, -3, 3, 0" />


thanks in advance :)


source to share

2 answers

Well finally I found another solution to solve this problem. I used RenderTransofrm to mirror control inside adorner like this:

        <TextBlock Name="watermarkTextBox" 
                    Text="{x:Static resources:Resources.SearchCodingTreeView}" 
                    RenderTransformOrigin="0.5,0.5" TextAlignment="Right">
            <ScaleTransform ScaleX="-1" />



place the axis of rotation in the control center and ScaleX="-1"

rotate it horizontally.



I think I saw some issues with Adorner on MSDN when I did some research with adorner (which I never used because they didn't fit my needs).

I can't find a link to where the issues with advertisers were discussed, but I'm sure it's not there.



All Articles