MuneeshKumar-3737 avatar image
0 Votes"
MuneeshKumar-3737 asked ·

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


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.





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


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


  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.

sshot-2.png (13.2 KiB)
sshot-1.png (6.6 KiB)
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you indent another 0.5, both cursors disappear.
textBoxView.Margin = new Thickness(-0.5, 0, 0, 0);

0 Votes 0 ·

@AlexLi-MSFT : I just want to remove default margin alone.

0 Votes 0 ·

Please update us the solution.

0 Votes 0 ·

TextBox reserves space for cursor input.If you don't want this space,you can set TextBox margin textBoxView.Margin = new Thickness(-0.5, 0, 0, 0);

0 Votes 0 ·

0 Answers