每次用户按下按钮时,我都想更改按钮的背景图像。我已将 ImageSource 设置为我的图片。当鼠标悬停在按钮上时,我的按钮不显示图像。如何设置图片以便即使鼠标悬停按钮仍然有图像?
<Button x:Name="recordButton" Content="" HorizontalAlignment="Left" Height="50" Margin="60,45,0,0" VerticalAlignment="Top" Width="50" Click="recordButton_Click">
<Button.Background>
<ImageBrush ImageSource="play.png"/>
</Button.Background>
</Button>
还有一个问题。这两张图怎么改?它们的名称是“play.png”和“stop.png”,都位于资源中。
private bool recordStarted = false;
private void recordButton_Click(object sender, RoutedEventArgs e)
{
recordStarted = !recordStarted;
if(recordStarted)
{
ImageBrush brush1 = new ImageBrush();
BitmapImage image = Properties.Resources.stop;
brush1.ImageSource = image;
recordButton.Background = brush1;
}
}
我已经尝试过了,但是 VS 找不到BitmapImage image = Properties.Resources.stop;
帮助,拜托!