WPF : Cursor not visible in text box first position in RightToLeft flow direction

Muneesh Kumar 1 Reputation point
2020-04-21T04:16:07.127+00:00

Hi,

I have tried to remove all margin value in TextBox by accessing inner element and set Margin as 0. With this value cursor not visible in RightToLeft direction first place. But working fine in LeftToRight direction.

LeftToRight:

<code>7538-sshot-2.png</code>

RightToLeft:

7556-sshot-1.png


You can see the cursor in LeftToRight direction-> First place. But the cursor not showing in RightToLeft direction first place.

XAML:

<StackPanel Margin="5">  
        <ContentControl Margin="10">  
            <TextBox Text="0.00" Loaded="TextBox_Loaded" />  
        </ContentControl>  
        <ContentControl Margin="10" FlowDirection="RightToLeft">  
            <TextBox Text="0.00" Loaded="TextBox_Loaded"/>  
        </ContentControl>  
    </StackPanel>  

C#:

 private void TextBox_Loaded(object sender, RoutedEventArgs e)  
        {  
            var frameworkElement = sender as FrameworkElement;  
            var container = VisualTreeHelper.GetChild(frameworkElement, 0) as FrameworkElement;  
            var contentElement = container.FindName("PART_ContentHost") as ScrollViewer;  

            if (contentElement != null && contentElement.Content is FrameworkElement)  
            {  
                var textBoxView = contentElement.Content as FrameworkElement;  
                textBoxView.Margin = new Thickness(0, 0, 0, 0);  
            }  
        }  

Thanks, Muneesh.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
{count} votes