WPF C# Tutorial – Create a simple clicking game in Visual Studio

Welcome to this new tutorial. In this tutorial we will be making a simple clicking game with WPF and C# inside of Visual Studio. This game will focus on the user clicking lots of circles inside of the canvas. When you click on a circle it will make a pop sound and disappear from the game and new ones will come out. Each time a new circle will spawn inside of the canvas it will start to grow slowly and when it gets bigger it pop on its own while making a pop sound. The idea behind this clicking game is to click and pop as many circles as possible before the health runs out. Each time a circle pops on its own it will reduce the in game health and when it reaches 0 a message box will pop up to tell you that the game has ended, you click OK on the message box to play again and it save your last score and display it on the screen while you are playing so you can aim to beat that score again on in the game.

Learning Objectives –

  • Explore how to create a simple clicking game inside of Visual Studio using WPF and C#
  • Spawn objects randomly to screen
  • Scale objects using the timer inside of the C# using a dispatcher timer and timer events
  • Link Mouse Click events to the Canvas inside of WPF
  • Remove unused resources from the game
  • import and play different sound files using media player class
  • Keep score and keep a last played score inside of the game
  • Make the game challenging by changing the speed, spawn rate and growth rates of the circles as the score increased

Full Video Tutorial –


Download the Sound Files here


XAML Code –

In this XAML code above you will see we have added a CANVAS to this WPF app and we removed the original GRID tag from there. In this canvas we have 3 different items presented at the moment. There are two Labels inside here and there are2 labels and 1 rectangle presented. The two labels are showing the current score and the last score from your game play. The red rectangle will be used to show the current health inside of the game. In this game we will spawn and ellipse objects dynamically from the C# code and it will be used to show them in the screen and the users will be able click and interact with them. For the click events if you notice that we have those

C# Code –




Comment on this tutorial and let us know how you got on -