Questo è il comportamento predefinito dello stile Aero per TextBox. Per disabilitarlo dovrai ridisporre il TextBox. È possibile utilizzare gli stili predefiniti da here (vedere Download di esempio).
Nello stile predefinito per TextBoxBase (su cui si basa TextBox), verrà visualizzato un ListBoxChrome. Questo elemento è definito nell'assembly Presentation.Aero ed è responsabile del rendering dell'aspetto "mirato". Puoi semplicemente rimuovere l'impostazione RenderFocus e possibilmente RenderMouseOver oppure sostituirlo con un bordo.
Quindi è necessario includerlo nelle risorse dell'applicazione.
<LinearGradientBrush x:Key="TextBoxBorder"
StartPoint="0,0" EndPoint="0,20" MappingMode="Absolute">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#ABADB3" Offset="0.05" />
<GradientStop Color="#E2E3EA" Offset="0.07" />
<GradientStop Color="#E3E9EF" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="{x:Type TextBoxBase}" TargetType="{x:Type TextBoxBase}" BasedOn="{x:Null}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="1" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border x:Name="Bd" BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
SnapsToDevicePixels="true">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border >
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBoxBase}}" TargetType="{x:Type TextBox}"/>
Se guardate la classe ListBoxChrome in Reflector (in particolare il metodo OnRender), si può vedere che renderà unico il look focalizzato se è BorderThickness è "1,1,1,1".
A cosa è impostato il DPI della scheda video? SnapToDevicePixels ha un effetto? –
Penso di essere in grado di riprodurre questo. Se si dispone di un controllo TextBox e viene attivato, il bordo cambia colore. Tuttavia, se BorderThickness è qualcosa di diverso da "1", questo non accade. Non ho mai visto questo, non penso di aver mai impostato il BorderThickness di un TextBox prima. (+1) –
@Hans, penso che SnapToDevicePixels non abbia alcun effetto ragionevole. I problemi si verificano solo se TextBox ottiene il punto focale (ad esempio uno sta scrivendo e il mouse viene spostato sul TextBox). – Jamie