我試圖創建一個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>