Muneeb Iqbal
Muneeb Iqbal

Reputation: 11

Internal Styling of TextBox in WPF not working

I want to change the border color of a text box when a user hovers his/her mouse over it. I tried this but failed.

<TextBox Name="a" Margin="20 50 50 150" >
    <TextBox.Resources>
        <Style TargetType="TextBox">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="BorderBrush" Value="Red"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Resources>
</TextBox>

Upvotes: 0

Views: 143

Answers (1)

Yosef Bernal
Yosef Bernal

Reputation: 1064

You put the style in the TextBox resource so it is not actually applied to it, it is only a resource. Try removing the resource tag, like this:

<TextBox Name="a" Margin="20 50 50 150" >
            <Style TargetType="TextBox">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="BorderBrush" Value="Red"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
</TextBox>

Upvotes: 1

Related Questions