title: Calculate Total hours between two time using Masked textbox in wpf
body: <p>I tried below code but not working proberly .calculate total hours between two time  using a masked textbox textchanged using wpf . Please help me</p>
  
  <p>xaml page:</p>
  
  <pre><code>&lt;msk:MaskedTextBox Grid.Row="0" Grid.Column="3" Margin="5,5,5,5" Height="30" Text="{Binding Path=FromTime}" Name="txt_starttime" Mask="00:00" HorizontalAlignment="Center" VerticalAlignment="Center" TextChanged="txt_totalhours_TextChanged" /&gt;
  
  &lt;msk:MaskedTextBox Grid.Row="0" Grid.Column="4" Margin="5,5,5,5" Height="30" Text="{Binding Path=ToTime}" Name="txt_endtime" Mask="00:00" HorizontalAlignment="Center" VerticalAlignment="Center" TextChanged="txt_totalhours_TextChanged"/&gt;
  &lt;TextBox Grid.Row="0" Grid.Column="5" Margin="5,5,5,5" Text="{Binding Path=TotalHours}" Name="txt_totalhours" TextChanged="txt_totalhours_TextChanged"/&gt;
  </code></pre>
  
  <p>code behind :</p>
  
  <pre><code>private void txt_totalhours_TextChanged(object sender, TextChangedEventArgs e)
      {
          if (null == txt_totalhours || null == txt_starttime || null == txt_endtime)
              return;
          //if (lb_weekDays.SelectedItems.Count &gt; 0)
          //{
          string StartTimeText = txt_starttime.Text;
          string EndTimeText = txt_endtime.Text;
          string[] Startparts = StartTimeText.Split(':');
          string[] Endparts = EndTimeText.Split(':');
          var resultStartHour = Int32.MinValue;
          var isIntstarttimeHour = Int32.TryParse(Startparts[0], out resultStartHour);
  
          var resultEndHour = Int32.MinValue;
          var isIntendtimeHour = Int32.TryParse(Endparts[0], out resultEndHour);
  
          var resultHour = isIntstarttimeHour ? ((isIntendtimeHour ? (resultEndHour - resultStartHour) : resultStartHour)) : (isIntendtimeHour ? resultEndHour : 0);
          int resHour = resultHour;
  
          var resultStartMin = Int32.MinValue;
          var isIntstarttimeMin = Int32.TryParse(Startparts[1], out resultStartMin);
  
          var resultEndMin = Int32.MinValue;
          var isIntendtimeMin = Int32.TryParse(Endparts[1], out resultEndMin);
  
          var resultMin = isIntstarttimeMin ? ((isIntendtimeMin ? (resultEndMin - resultStartMin) : resultStartMin)) : (isIntendtimeMin ? resultEndMin : 0);
          int resMin = resultMin;
          int lbCount = lb_weekDays.SelectedItems.Count;
  
          int ab = 0, abc = 0;
          ab = resHour * lbCount;
          abc = resMin * lbCount;
          if (abc &gt; 59)
          {
              int quotient = 0;
              quotient = abc / 60;
              ab = ab + quotient;
  
              int remainder = 0;
              remainder = abc % 60;
              abc = remainder;
          }
          txt_totalhours.Text = ab + ":" + abc;
          //}
          //else
          //{
          //    MessageBox.Show("Please Select WeekDays Before Enter Time");
          //}
  
      }
  </code></pre>