title: WPF data binging variables to element properties - General binding information
body: <p>I have a question with regards to WPF bindings.</p>
  <p>I cannot find clear explanations of how it works. Sure, the Microsoft docs webpage provides a lot of information, but this documentation does not clarify a lot for me. After reading the documentation I go back to my code with the conclusion that WPF bindings are too complicated and that I try to make due using event handlers instead.</p>
  <p>I believe that I don't have to go through the hassle of using event handlers and all, and I believe that WPF databingings would improve my code a lot, making it more elegant and simple. Yet, up until now, I haven't been able to find a simple explanation and I haven't been able to get it working without just copy-pasting big pieces of code from the internet. Code I do not understand.</p>
  <p>I've tried lots of StackOverflow posts and youtube videos but not much seems to work.</p>
  <p>Let me show you what I'm trying to do. I have a wheel (cog) that I want to rotate. I want to manipulate that rotation programmatically. For the sake of the example, I will increase a rotation angle by one degree every second.</p>
  <p>When I stop the debugger in the incrementation loop, I can see that the variable that holds the rotation angle has a value, that increases over time. I can also see that, when I hover over that property (variable) in the XAML part of the code, this property does have the correct value. The issue is that my UI element, that wheel I made, does not rotate.</p>
  <p><a href="https://i.stack.imgur.com/lSp9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lSp9e.png" alt="Debugging my code" /></a></p>
  <p>Can anyone tell me what I'm doing wrong here?
  And does anyone have suggestions or sources when I can find a good explanation of how to use bindings in WPF?</p>
  <p>Thanks in advance.</p>
  <p>My code:</p>
  <p><strong>MainWindow.xaml</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class=&quot;PropertyBindingWPF.MainWindow&quot;
          xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
          xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
          xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
          xmlns:local=&quot;clr-namespace:PropertyBindingWPF&quot;
          mc:Ignorable=&quot;d&quot;
          Title=&quot;MainWindow&quot; Height=&quot;250&quot; Width=&quot;400&quot;&gt;
      
      &lt;Grid&gt;
          &lt;StackPanel&gt;
              &lt;Canvas&gt;                
                  &lt;Canvas Name=&quot;Wheel&quot; 
                          Canvas.Top=&quot;80&quot; 
                          Canvas.Left=&quot;150&quot; 
                          RenderTransformOrigin=&quot;.5 .5&quot; 
                          Width=&quot;100&quot; 
                          Height=&quot;100&quot;&gt;
                      &lt;Canvas.RenderTransform&gt;
                          &lt;RotateTransform Angle=&quot;{Binding Path=CogRotationAngle}&quot;/&gt;
                      &lt;/Canvas.RenderTransform&gt;
                      
                      &lt;Ellipse Width=&quot;90&quot; 
                               Height=&quot;90&quot; 
                               StrokeThickness=&quot;2&quot; 
                               Stroke=&quot;Black&quot; 
                               Fill=&quot;White&quot; 
                               Canvas.Top=&quot;5&quot; 
                               Canvas.Left=&quot;5&quot;/&gt;
                      
                      &lt;Ellipse Width=&quot;3&quot; 
                               Height=&quot;3&quot; 
                               StrokeThickness=&quot;2&quot; 
                               Stroke=&quot;Blue&quot; 
                               Canvas.Left=&quot;48.5&quot; 
                               Canvas.Top=&quot;10&quot;/&gt;
                  &lt;/Canvas&gt;
              &lt;/Canvas&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
      
  &lt;/Window&gt;
  </code></pre>
  <p><strong>MainWindow.xaml.cs</strong></p>
  <pre class="lang-cs prettyprint-override"><code>using System.Windows;
  using System.Threading;
  
  namespace PropertyBindingWPF
  {
      public partial class MainWindow : Window
      {
          public int CogRotationAngle { get; set; }
  
          public MainWindow()
          {
              InitializeComponent();
  
              DataContext = this;
  
              Thread loop = new Thread(LoopThread);
              loop.Start();
          }
  
          private void LoopThread()
          {
              while (true)
              {
                  CogRotationAngle++;
                  if (CogRotationAngle &gt;= 360) CogRotationAngle = 0;
  
                  Thread.Sleep(1000);
              }
          }
      }
  }
  </code></pre>