我正在尝试创建一个UWP按钮,当鼠标指针悬停在它上面时会改变背景颜色.我遇到的麻烦是,默认情况下,似乎已经这样做了,但不是我想要的颜色.当我将鼠标悬停在我的按钮(红色)上时,它会变为默认灰色,然后在我鼠标移出时返回.我在C#中编写代码,试图在我将鼠标悬停在它上面时变成蓝色
private void button_PointerEntered_1(object sender, PointerRoutedEventArgs e)
{
button.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 255));
}
private void button_PointerExited_1(object sender, PointerRoutedEventArgs e)
{
button.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 0, 0));
}
Run Code Online (Sandbox Code Playgroud)
下面是按钮的XAML代码
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button x:Name="button"
Content="Button"
HorizontalAlignment="Left"
Margin="417,188,0,0"
VerticalAlignment="Top"
Height="230"
Width="461"
FontSize="72"
ManipulationMode="None"
PointerEntered="button_PointerEntered_1"
PointerExited="button_PointerExited_1">
<Button.Foreground>
<SolidColorBrush Color="Black"/>
</Button.Foreground>
<Button.Background>
<SolidColorBrush Color="Red"/>
</Button.Background>
</Button>
</Grid>
Run Code Online (Sandbox Code Playgroud)