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;

        #endregion

        #region Constructor

        public WatermarkAdorner(UIElement adornedElement, object watermark) :
            base(adornedElement)
        {
            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);
        }

        #endregion

        #region Protected Properties

        protected override int VisualChildrenCount
        {
            get { return 1; }
        }

        #endregion

        #region Private Properties

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

        #endregion

        #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
            this.contentPresenter.Measure(Control.RenderSize);
            return Control.RenderSize;
        }

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

        #endregion
    }

}

      

and i use it:

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

      

thanks in advance :)

+3


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:

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

      



RenderTransformOrigin="0.5,0.5"

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

rotate it horizontally.

+2


source


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.

0


source







All Articles