我试图创建一个UWP按钮,它将在鼠标指针悬停在其上时更改背景颜色。我遇到的麻烦是,默认情况下,它似乎已经这样做,但不是我想要的颜色。当我将鼠标悬停在红色的按钮上时,它会变成默认的灰色,然后当我将鼠标移出时再回来。我在C#编写代码,试图使它变成蓝色,当我在它悬停UWP按钮在鼠标悬停时更改颜色
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));
}
下面是按钮的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>