title: When does binding actually happen
body: <p>On a popup window I have a <code>checkbox.IsChecked</code> bound to a model, but I want to check its state from the xaml code behind when the window is displayed. When checking the checkbox by name in the code behind from the windows loaded event it is not set yet. There are some UI specific things that I need to do and that is why I need to know what the checkboxes value is when the window opens and i cannot perform this from the model that the checkbox.IsChecked is bound to. </p>
  
  <p>The property on the model is set long before the popup window is opened, so it is not an issue of the binding not being there. I figured that once the Loaded event fires the window would be ready to use bindings and all, but this does not seem to be the case.</p>
  
  <p>Xaml:</p>
  
  <pre><code>&lt;RefinedRibbonControls:RefinedRibbonGroup Header="Show Graphs"&gt;
                      &lt;StackPanel x:Name="panelVisibilities"&gt;
                          &lt;CheckBox Content="Show/hide" x:Name="myCheckBox"                                 
                                    IsChecked="{Binding Path=Processor.Model.IsItemVisible}"
                                    Click="GraphVisibilityClickEvent"
                                    HorizontalAlignment="Left"/&gt;
  ...etc
  </code></pre>
  
  <p>Property on model:</p>
  
  <pre><code>public bool IsItemVisible
          {
              get { return _isItemVisible ; }
              set
              {
                  if (_isItemVisible != value)
                  {
                      _isItemVisible = value;
                      _propertyChanger.FirePropertyChanged(this, m =&gt; m.IsItemVisible);
                  }
              }
          }
  </code></pre>
  
  <p>Event in Xaml codebehind:</p>
  
  <pre><code>private void WindowLoadedEvent(object sender, RoutedEventArgs e)
          {
              if(myCheckBox.IsChecked.Value)
              {
                  // Do UI Related Stuff
              }
           }
  </code></pre>
  
  <p>The binding works fine and the values show up when the window is displayed, the problem is I cannot get the value of the binding in the window loaded event.</p>
  
  <p>Edit: Possible solution I have found but I am not sure if its the best way.
  I called the following method from the constructor on the xaml code behind.</p>
  
  <pre><code>private void SetupInitialVisibility()
          {
              //Fire after everything is loaded.
              Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() =&gt;
              {
                  IEnumerable&lt;CheckBox&gt; elements = this.panelVisibilities.Children.OfType&lt;CheckBox&gt;().ToList();
                  foreach (CheckBox checkBox in elements)
                  {
                      if (checkBox.IsChecked != null &amp;&amp; checkBox.IsChecked.Value == false)
                      {
                          //Do work
                      }
                  }
  
  
              }));
          }
  </code></pre>
  
  <p>found at: <a href="https://stackoverflow.com/a/1746975/1253746">https://stackoverflow.com/a/1746975/1253746</a></p>