user3913568
user3913568

Reputation: 1

C# A namespace cannot directly contain members such as fields or methods for void

This is my code im trying to make a stop, pause and start button and im fairly new to programming but the void bit is giving me an error, A namespace cannot directly contain members such as fields or methods.

void MusicPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
{
    switch (musicPlayer.CurrentState)
    {
        case MediaElementState.Playing:
            systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;
            break;
        case MediaElementState.Paused:
            systemControls.PlaybackStatus = MediaPlaybackStatus.Paused;
            break;
        case MediaElementState.Stopped:
            systemControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
            break;
        case MediaElementState.Closed:
            systemControls.PlaybackStatus = MediaPlaybackStatus.Closed;
            break;
        default:
            break;
}

}

Upvotes: 0

Views: 1601

Answers (1)

Mwigs
Mwigs

Reputation: 231

You are probably lacking a class and is writing the method directly in the namespace.

Upvotes: 1

Related Questions