Text box styling

Whenever I try to apply a style to a text field, it becomes immune to user input. Can you tell me how to solve this? Here is the xaml code I'm using:

<Style x:Key="textbox" TargetType="TextBox"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TextBox"> <Border BorderThickness="3" Background="{TemplateBinding Background}" Name="border"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="BorderBrush" Value="#9E5971" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 
+4
source share
1 answer

Replace

 <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> 

with

 <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 

ScrollViewer named PART_ContentHost is a required part of any TextBox control template. You should use the default WPF Standard Styles and Templates as a reference, instead of coming up with your own custom template.

+6
source

Source: https://habr.com/ru/post/1488968/


All Articles