WPF TextBox插入符号消失

La *_*bla 5 c# wpf caret

我正在开发具有TextBox组件的WPF应用程序。

我的文本框的插入符号有问题。似乎,根据其TextBox自身的位置,插入号在某些特定位置消失了

插入符号显示:

插入符号显示

插入符号消失:

插入符号消失

插入符返回:

在此处输入图片说明

TextBox样式很简单:

<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>
Run Code Online (Sandbox Code Playgroud)

我什至尝试将字体设置Courier New为等宽字体。

Aly*_*dad 3

这个问题似乎在尺度变换中很常见(1 , 2),它是由您在评论中提到的行为所应用的。

mainElement.LayoutTransform = scaleTransform;
Run Code Online (Sandbox Code Playgroud)

MSDN来看,没有

此问题的有效解决方案。

所以,如果你想支持多分辨率,我会推荐ViewBox;简单,然后完成工作。

  • 谢谢,我尝试用 ViewBox 替换 Behaviour,但它没有解决插入符问题,有时仍然丢失。 (2认同)