C
C#2y ago
kuulie

✅ How to add hover effect to WPF button element

This code I'm using isn't working. When I hover over buttons its a lightblue color. <Style TargetType="Button"> <Setter Property="FontSize" Value="18" /> <Setter Property="FontWeight" Value="Medium" /> <Setter Property="Foreground" Value="#262626" /> <Setter Property="Background" Value="#ECECEC" /> <Setter Property="BorderThickness" Value="0" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="#E0E0E0" /> </Trigger> </Style.Triggers> </Style>
2 Replies
goooosee
goooosee2y ago
<ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter Property="Background" TargetName="border" Value="#dbd94d"/> </Trigger> <Trigger Property="IsMouseOver" Value="True" /> <EventTrigger RoutedEvent="Border.MouseEnter" SourceName="border"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Color" From="#202020" To="#dbd94d" Duration="0:0:0.2" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="Border.MouseLeave" SourceName="border"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Color" From="#dbd94d" To="#212121" Duration="0:0:0.2" /> </Storyboard> </BeginStoryboard> </EventTrigger> </ControlTemplate.Triggers> just change IsPressed to HoverUp mouse or smtg IsMouseOver
kuulie
kuulieOP2y ago
um, which part of your code am i supposed to be looking at? You're also using ControlTemple.Triggers and I was using Style.Triggers. Am I usign the wrong elements i made another project simply practice hovering and please tell me what im doing wrong with this code: <Window.Resources> <Style TargetType="Button"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Green"/> </Trigger> </Style.Triggers> </Style> </Window.Resources> <Grid> <Button Content="Button"/> </Grid>
Want results from more Discord servers?
Add your server