title: How to update the value of progressbar and textblock in wpf
body: <p>I'm new to wpf and c# and also in asking here. I am searching the web for hours and i haven't found a solution for my problem. I have a progress bar that updates it's value whenever the loop increments and a textblock that updates it's text (ex: Reading Lines 5/3000). Currently, I don't have the binding path so i make a dummy binding in my xaml. I don't know exactly how to make it work.</p>
  
  <p>Here's my XAML:</p>
  
  <pre><code>&lt;xctk:BusyIndicator x:Name="_busyIndicator" Grid.Row="4"&gt;
                  &lt;xctk:BusyIndicator.BusyContentTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Margin="4"&gt;
                              &lt;TextBlock Text="Parsing OTM File" FontWeight="Bold" HorizontalAlignment="Center" /&gt;
                              &lt;StackPanel Margin="4"&gt;
                                  &lt;TextBlock Text="{Binding NumberOfLinesOfStringInTextFile}" /&gt;
                                  &lt;ProgressBar Grid.Row="4" Name="prgParse" Height="15" Value="{Binding CurrentLineNumberAddedToListView}" /&gt;
                              &lt;/StackPanel&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/xctk:BusyIndicator.BusyContentTemplate&gt;
                  &lt;xctk:BusyIndicator.OverlayStyle&gt;
                      &lt;Style TargetType="Rectangle"&gt;
                          &lt;Setter Property="Fill" Value="#ffffeeee"/&gt;
                      &lt;/Style&gt;
                  &lt;/xctk:BusyIndicator.OverlayStyle&gt;
                  &lt;xctk:BusyIndicator.ProgressBarStyle&gt;
                      &lt;Style TargetType="ProgressBar"&gt;
                          &lt;Setter Property="Visibility" Value="Collapsed"/&gt;
                      &lt;/Style&gt;
                  &lt;/xctk:BusyIndicator.ProgressBarStyle&gt;
                  &lt;ListBox x:Name="_listBox" /&gt;
              &lt;/xctk:BusyIndicator&gt;
  </code></pre>
  
  <p>I have a button that triggers the loop that reads the lines inside the text file (in this case it has 3000+ lines) and places the line of string to the listview. I want to update the textblock in my xaml that states "Reading Lines 300/3000" and the progressbar indicating it's percentage which updates its value to 10 or 10% while it is transferring the data to the listview.</p>
  
  <p>Here is my code behind:</p>
  
  <pre><code> public partial class MainWindow : Window, INotifyPropertyChanged
      {
  
          public MainWindow()
          {
              InitializeComponent();
              DataContext = this;
  
          }
  
          private void cmdBrowse_Click(object sender, RoutedEventArgs e)
          {
  
              var OpenOTM = new Microsoft.Win32.OpenFileDialog();
              OpenOTM.DefaultExt = ".otm";
              OpenOTM.Filter = "OTM Files (*.otm)|*.otm|TEXT Files (*.txt)|*.txt"; 
  
              if (OpenOTM.ShowDialog().GetValueOrDefault(false))
              {
                  txtFilePath.Text = OpenOTM.FileName;
              }
          }
  
          private void cmdOk_Click(object sender, RoutedEventArgs e)
          {
              WithAdjustments wa = new WithAdjustments();
              BackgroundWorker worker = new BackgroundWorker();
  
              string[] lines = System.IO.File.ReadAllLines(txtFilePath.Text);
              worker.DoWork += (o, ea) =&gt;
              {
                  List&lt;String&gt; listOfString = new List&lt;string&gt;();
                  foreach (string lin in lines)
                  {
                      listOfString.Add(lin);
                      Thread.Sleep(2);
                  }
  
                  Dispatcher.Invoke((Action)(() =&gt; _listBox.ItemsSource = listOfString));
              };
              worker.RunWorkerCompleted += (o, ea) =&gt;
              {
                  _busyIndicator.IsBusy = false;
              };
              _busyIndicator.IsBusy = true;
              worker.RunWorkerAsync();
          }
      }
  </code></pre>
  
  <p>Thanks in advance! I hope someone can help me :)</p>