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.

Choosing the PeerCast application mode

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) ...

Get Coding4Fun now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.