【发布时间】:2016-12-11 05:57:34
【问题描述】:
我正在尝试创建一个 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));
}
下面是按钮的 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>
【问题讨论】: