我最近开始学习 WPF。我遇到了一个问题,当你指向按钮时,它会变成蓝色。我搜索了互联网并找到了解决问题的方法。我在按钮上做了一个样式。但问题是,按钮上的样式没有应用。PS 按钮内的元素具有透明背景。
风格:
<Style x:Key = "TriggerStyle" TargetType = "Button">
<Setter Property = "Foreground" Value = "Blue" />
<Style.Triggers>
<Trigger Property = "IsMouseOver" Value = "True">
<Setter Property = "Foreground" Value = "Green" />
</Trigger>
</Style.Triggers>
</Style>
按钮:
<DockPanel HorizontalAlignment="Left" Width="200"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="#FF141414">
<Button Content="Main" Height="45" VerticalAlignment="Top" Width="200" DockPanel.Dock="Top"
Style="{StaticResource ButtonSubMenu}" FontSize="22"/>
<StackPanel Height="114" VerticalAlignment="Top" Width="200" Background="#FF232323">
<Button Style="{StaticResource TriggerStyle}" Height="30" Background="#FF2D2D2D"
Foreground="White" HorizontalAlignment="Left" Width="200" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" Width="181" Height="30">
<fa:ImageAwesome Icon="Terminal" Foreground="White" HorizontalAlignment="Right"
Width="26" StretchDirection="DownOnly" Height="22" Margin="0,4"/>
<TextBlock Text="Console" FontSize="18" Margin="10,0,0,0"
HorizontalAlignment="Left"/>
</StackPanel>
</Button>
</StackPanel>
</DockPanel>
要更改 MouseOver 上的默认行为,您需要更改 ControlTemplate 尝试:
原文:https ://stackoverflow.com/questions/17259280/how-do-you-change-background-for-a-button-mouseover-in-wpf