how to change color in triggers in wpf?

mc 5,796 Reputation points
2025-08-15T13:02:30.98+00:00

<Style.Triggers>

<Trigger Property="IsMouseOver" Value="True">

<Setter Property ="Background" Value="#ffffff/>

</Trigger>

</Style.Triggers>

the color is still the original when the mouse is over

Developer technologies | Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Starry Night 115 Reputation points
    2025-08-18T01:39:14.2266667+00:00

    I couldn't see your other codes, but you can try the following code, which works on my side.

            <Rectangle Name="rctback" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="100" Margin="178,92,0,0" >
                <Rectangle.Style>
                    <Style TargetType="Rectangle">
                        <Setter Property="Fill" Value="Green"></Setter>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Fill" Value="Red" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Rectangle.Style>
            </Rectangle>
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.