Building the Application UI
At this point, we've covered all of the network communication in the NetworkManager class, but we haven't built the actual application UI, which is the next step in building PeerCast.
Choosing the Application Mode
When PeerCast first runs, the ChooseMode.xaml window will load, as shown in Figure 5-8, with two buttons, one named Client and another named Server, representing the two application modes.

Figure 5-8. Choosing the PeerCast application mode
Both buttons have the same click event, SetMode, which sets the application-level IsServerMode variable defined in Example 5-61 and Example 5-62. The code also opens the MainWindow.xaml window and closes the ChooseMode.xaml window, as shown in Example 5-59 and Example 5-60.
Example 5-59.
The ChooseMode Button event handler in C#
private void SetMode(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
if (button.Name == "Server")
{
App.IsServerMode = true;
}
else
{
App.IsServerMode = false;
}
//open Main Window
MainWindow w = new MainWindow();
w.Show();
//close current Window
this.Close();
}Example 5-60.
The ChooseMode Button event handler in VB
Private Sub SetMode(ByVal sender As Object, ByVal e As RoutedEventArgs) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access