ComponentOne Gauges for WPF and Silverlight
WPF Quick Start / Step 2 of 3: Adding Code to the Application
In This Topic
    Step 2 of 3: Adding Code to the Application
    In This Topic

    In the previous step you created a new WPF project and added Gauges for WPF controls to the application. In this step you'll add code to your application to customize it.

    Complete the following steps:

    1. Double-click TextBox1 to switch to Code view and create the TextBox1_TextChanged event handler.
    2. Add the following imports statements to the top of the page:
      Visual Basic
      Copy Code
      Imports C1.WPF
      Imports C1.WPF.Gauge
      

      C#
      Copy Code
      using C1.WPF;
      using C1.WPF.Gauge;
      
    3. Add code to the TextBox1_TextChanged event handler so that it appears like the following:
      Visual Basic
      Copy Code
      Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles TextBox1.TextChanged
          Me.C1LinearGauge1.Value = Me.TextBox1.Text
          Me.C1RadialGauge1.Value = Me.TextBox1.Text
          Me.C1Knob1.Value = Me.TextBox1.Text
      End Sub
      

      C#
      Copy Code
      private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
      {
          this.c1LinearGauge1.Value = Convert.ToDouble(this.textBox1.Text);
          this.c1RadialGauge1.Value = Convert.ToDouble(this.textBox1.Text);
          this.c1Knob1.Value = Convert.ToDouble(this.textBox1.Text);
      }
      

      When a number is entered in the text box at run time, the value of the gauge controls will be set to that number.

    4. Choose View | Designer to return to Design view.
    5. Click C1Knob1 to select it, and navigate to the Properties window.
    6. Click the Events (lightning bolt) button on the Properties window to view events.
    7. Double-click the box next to the ValueChanged event. This will switch to Code view and create the C1Knob1_ValueChanged event handler.
    8. Enter the code in the C1Knob1_ValueChanged event handler to set the gauge and text box control values. It will look like the following:
      Visual Basic
      Copy Code
      Private Sub C1Knob1_ValueChanged(ByVal sender As System.Object, ByVal e As C1.WPF.PropertyChangedEventArgs(Of System.Double)) Handles C1Knob1.ValueChanged
          Me.C1LinearGauge1.Value = Me.C1Knob1.Value
          Me.C1RadialGauge1.Value = Me.C1Knob1.Value
          Me.TextBox1.Text = Me.C1Knob1.Value.ToString
      End Sub
      

       

      C#
      Copy Code
      private void c1Knob1_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
      {
          this.c1LinearGauge1.Value = this.c1Knob1.Value;
          this.c1RadialGauge1.Value = this.c1Knob1.Value;
          this.textBox1.Text = Convert.ToString(this.c1Knob1.Value);
      }
      
    In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.