I’m working on a trivia kahoot style game, where the client is based on the WPF framework (hello to all fellow magshimim students with the same issue)
When loading the game window, which is supposed to request and display questions from the server, the window shows up blank. There are no compilation errors or runtime exceptions, and I when clicking on the minimized window in the taskbar it doesn’t open.
public GameQuestionWindow(Communicator communicator, MenuWindow menu, int timePerQuestion, int questionsLeft, Window prevWindow)
{
this.Show();
InitializeComponent();
prevWindow.Close();
m_communicator = communicator;
m_questionsLeft = questionsLeft;
m_menuWindow = menu;
m_mediaPlayer = new MediaPlayer();
m_mediaPlayer.Open(new Uri("pack://application:,,,/Client;component/Audio/tick.mp3"));
time = TimeSpan.FromSeconds(timePerQuestion);
timer = new DispatcherTimer();
gameLoop();
}
I’ve tried performing this.Show()
after the initialization instead, or using ShowDialog(), but the problem with the latter is that none of the background game logic is executed and the thread is halted, while the window is once again blank.
This is how the window is created:
if (serverResp.getCode() == 150)
{
shouldStop = true;
GameQuestionWindow window = new GameQuestionWindow(this.communicator, this.menuWindow, answerTimeout, answerAmount, this);
}
shouldStop
is for a background refresh thread and is irrelevant.
I cannot put window.Show() after the constructor since all game logic is executed on the main thread in from the constructor as shown previously, meaning if Show() is called after the constructor returns, it’ll only be after the game is done, as long as the calling window isn’t closed before, which it is.
In the visual studio XAML designer the game window is shown without problem.
The window shown before the game
The blank game window