Basic Library for WPF and Silverlight | ComponentOne
WPF and Silverlight Edition Basic Library / Windows / Windows Quick Start / Step 3 of 4: Adding Code
In This Topic
    Step 3 of 4: Adding Code
    In This Topic

    In the previous steps you set up the application's user interface and added controls to your application. In this step you'll add code to your application to finalize it.

    Complete the following steps:

    1. Return to the Design view of the form.
    2. Select Button1 on the form, navigate to the Properties window, click the lightning bolt Events icon to view events, and click the space next to the Click item to create a Button1_Click event handler and switch to Code view.
    3. Return to Design view and repeat the previous step with Button2 to create the Button2_Click event handler.
    4. In Code view, add the following import statement to the top of the page:
    Visual Basic
    Copy Code
    Imports C1.WPF
    OR
    Imports C1.Silverlight
    

     

    C#
    Copy Code
    using C1.WPF;
    OR
    using C1.Silverlight;
    
    1. Add the following code to the event handlers added earlier:
    Visual Basic
    Copy Code
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ShowWindow(False)
    End Sub
    Private Sub Button2_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ShowWindow(True)
    End Sub
    

     

    C#
    Copy Code
    void button1_Click(object sender, RoutedEventArgs e)
    {
      ShowWindow(false);
    }
    void button2_Click(object sender, RoutedEventArgs e)
    {
      ShowWindow(true);
    }
    
    1. Add the following code below the Button_Click event handlers:
    Visual Basic
    Copy Code
    Private Sub ShowWindow(ByVal showModal As Boolean)
        Dim wnd As New C1Window()
        wnd.Header = "This is the header."
        wnd.Height = 120
        wnd.Width = 200
        wnd.Content = New MyWindow()
        wnd.CenterOnScreen()
        If showModal Then
            wnd.ShowModal()
        Else
            wnd.Show()
        End If
    End Sub
    

     

    C#
    Copy Code
    private void ShowWindow(bool showModal)
    {
        C1Window wnd = new C1Window();
        wnd.Header = "This is the header.";
        wnd.Height = 120;
        wnd.Width = 200;
        wnd.Content = new MyWindow();
        wnd.CenterOnScreen();
        if (showModal)
          wnd.ShowModal();
        else
          wnd.Show();
    }
    

     This code specifies the size of the window and opens a new window.

    In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.