title: Bind properties of a class to a WPF button
body: <p>So I want to bind 2 properties of a class that are inside of a List in a List to the Content of dynamically generated Button in my WPF program.</p>
  
  <p>This is the XAML I have so far that binds the dynamically generated buttons as a 2D grid</p>
  
  <pre><code> &lt;Window.Resources&gt;
      &lt;DataTemplate x:Key="DataTemplate_Level2"&gt;
          &lt;Button Height="35" Width="35" Margin="-1,-1,-1,-1" IsEnabled="{Binding}" x:Name="fieldButton" Click="fieldClick" Content="{Binding}"/&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate x:Key="DataTemplate_Level1"&gt;
          &lt;ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate_Level2}"&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal"/&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
          &lt;/ItemsControl&gt;
      &lt;/DataTemplate&gt;
  
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;ItemsControl x:Name="lst" ItemTemplate="{DynamicResource DataTemplate_Level1}" Margin="0,0,339,0"&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Here is the class that created the Grid and fills the attributes of the class with the correct values</p>
  
  <pre><code>class Grid {
  
      private const int SIZE = 10;
      private List&lt;List&lt;Field&gt;&gt; fields;
  
      public Grid() {
          fields=new List&lt;List&lt;Field&gt;&gt;();
  
          for(int i = 0; i &lt; SIZE; i++) {
              fields.Add(new List&lt;Field&gt;());
              for(int j = 0; j &lt; SIZE; j++) {
                  fields[i].Add(new Field(i, j));
              }
          }
      }
  
      public List&lt;List&lt;Field&gt;&gt; getFields() {
          return fields;
      }
  }
  </code></pre>
  
  <p>And here is the class that has the filled attributes</p>
  
  <pre><code>class Field {
      private int x;
      private int y;
  
      public Field(int x,int y) {
          this.x = x;
          this.y = y;
      }
  }
  </code></pre>
  
  <p>Currently the Grid shows ".Field" as Content for every button. I want it to be "x,y" though. </p>
  
  <p>Thanks for the help in advance.</p>