1

Why does a border appear around a TextBox when a Style is used as opposed to no Style being used? Is there a way to set this using a Style so no border appears, like in the "Phone" Grid/TextBox? See below:

enter image description here

WINDOW XAML

 <!-- City, State, Zip --> <Grid Grid.Column="0" Grid.Row="2" Background="White" Margin="50,2,25,2"> <Viewbox> <TextBox Style="{Binding StandardTextBox1}" Text="{Binding CityStateZip}"/> </Viewbox> </Grid> <!-- Phone --> <Grid Grid.Column="0" Grid.Row="3" Background="White" Margin="50,2,25,2"> <Viewbox> <TextBox Background="Transparent" BorderBrush="Transparent" Text="{Binding FacilityPhoneMain}" TextAlignment="Center" FontSize="14" /> </Viewbox> </Grid> 

STYLE XAML

<!-- Standard TextBox 1 --> <Style TargetType="TextBox" x:Key="StandardTextBox1"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="TextAlignment" Value="Center"/> <Setter Property="FontSize" Value="14"/> </Style> 
1
  • Are you sure that your textbox is at fault? Do you have any Visual Tree inspection tool at hand (like Snoop, or some recent Visual Studio versions have this ability). You should probably just select the unexpected rectangle at runtime and check the value source for the borderbrush. Commented Feb 8, 2018 at 7:19

1 Answer 1

0

You can modify the BorderThickness property of the TextBox in your Style to remove the border.

As for why the border is not affected in the Style, I have a hunch that this is due to dependency property precedence.

Animations have a higher precedence than property setters. Due to the default WPF Textbox template having animations that affect the BorderBrush property, the setters are not being applied.

This link has some relevant information

To quote: "Animation values always take precedence over local values, setters and triggers"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.