Ошибка: необходимо исправить код. c#

ЯП - c#; WPF.

Мне нужно сделать так, чтобы при нажатии на картинку выдавалась другая картинка, я пытаюсь сделать это следующим образом:

private void play(object sender, RoutedEventArgs e)
    {

         Image content = (Image)play_pause.Content;
        if (((BitmapImage)content.Source).UriSource == new Uri("Resources/pause.png", UriKind.Relative))
        {
            timer.Start();
            MessageBox.Show("Вошел");
            content.Source = new BitmapImage(new Uri("Resources/pause.png", UriKind.Relative));
            foreach (UIElement i in pole.Children)
            {
                if (i is Button)
                {
                    ((Button)i).IsEnabled = true;
                }
            }
        }
        else
        {
            timer.Stop();
            MessageBox.Show("Вошел во 2 if");
            content.Source = new BitmapImage(new Uri("Resources/play.png", UriKind.Relative));
            foreach (UIElement i in pole.Children)
            {
                if (i is Button)
                {
                    ((Button)i).IsEnabled = false;
                }
            }
        }


    }

Но при компиляции выдает такую вот ошибку:

System.InvalidCastException: "Не удалось привести тип объекта "System.Windows.Media.Imaging.BitmapFrameDecode" к типу "System.Windows.Media.Imaging.BitmapImage"."

Как исправить?


Ответы (0 шт):