Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBox Caret Disappearing

Tags:

c#

wpf

caret

I'm developing a WPF application that has TextBox components.

I'm having a problem with the caret of the text boxes. It seems that, depending on the location of the TextBox itself, the caret disappears on certain specific locations

Caret showing:

Caret showing

Caret disappears:

Caret disappears

Caret returns:

enter image description here

The TextBox style is very simple:

<Style TargetType="{x:Type TextBox}" x:Key="FormTextBox">
    <Setter Property="Width" Value="464"/>
    <Setter Property="Height" Value="74"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="FontFamily" Value="Microsoft Sans Serif"/>
    <Setter Property="FontSize" Value="43.2"/>
    <Setter Property="MaxLength" Value="50"/>
</Style>

I tried even setting the font to Courier New which is monospace font, same thing.

like image 417
La bla bla Avatar asked Dec 25 '16 09:12

La bla bla


1 Answers

The problem seems to be common (1, 2) with the scale transformation, which is being applied by the behavior you mentioned in comments.

mainElement.LayoutTransform = scaleTransform;

And from MSDN, there's no

effective solution for this issue.

So, if you want to support multi-resolution, I would recommend ViewBox; simple, and do the job.

like image 193
Aly Elhaddad Avatar answered Oct 22 '22 02:10

Aly Elhaddad