ユーザーがボタンを押すたびに、ボタンの背景画像を変更したいのですが。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>
そして別の質問。これらの2つの写真を変更するにはどうすればよいですか?それらの名前は「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;
ヘルプを見つけることができません。