It almost gets me mad in recent days. I have a textbox and the style in xaml file. But the style without a control template cannot take effect on textbox. Whereas, a control template works, but control template seems to overwrite the textbox totally, the default behaviors loses of textbox such as editing, inputing or selecting... Here is content of xaml with the control template:
<Style TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border Name="tbBorder" Background="White" BorderThickness="0.6" BorderBrush="#B9B9B9"> <ContentPresenter/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="true"> <Setter Property="BorderBrush" Value="#4D90FE" /> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="BorderBrush" Value="#4D90FE" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> And here is the simple style which does not work at all,
<Style TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="IsFocused" Value="true"> <Setter Property="BorderBrush" Value="#4D90FE" /> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="BorderBrush" Value="#4D90FE" /> </Trigger> </Style.Triggers> </Style> Thanks!
update: the entire textbox's code snipt:
<TextBox Height="23" HorizontalAlignment="Left" Margin="114,53,0,0" Name="textBox1" VerticalAlignment="Top" Width="150" Text="{Binding Path=TraderAccount, Mode=OneWayToSource, NotifyOnValidationError=True}" BorderBrush="#FFB9B9B9" BorderThickness="1" > <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="IsFocused" Value="true"> <Setter Property="BorderBrush" Value="Red" /> </Trigger> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="BorderBrush" Value="Red" /> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>