Reputation: 394
I'm trying to create a textbox template in WPF, which has a single line of text and a flat (non-3d) border. If the text is too large for the field, it should scroll horizontally without showing scroll bar (like an address or search bar in a browser.) However with my code, when the text is wider than the textbox, it stills goes to a new line. My xaml is as follows:
<Style TargetType="TextBox" x:Key="SingleLineTextBox">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="CaretBrush" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border SnapsToDevicePixels="True" BorderThickness="1" BorderBrush="Gray" Background="White">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Can anyone tell me what I'm missing here?
Upvotes: 0
Views: 1826