title: WPF rectangle color binding
body: <p>I'm trying to write grid of rectangles, which does change color of its objects.</p>
  <pre><code>  private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          for (int i = 0; i &lt; size; i++)
          {
              main_grid.ColumnDefinitions.Add(new ColumnDefinition());
              main_grid.RowDefinitions.Add(new RowDefinition());
          }
          for (int i = 0; i &lt; size; i++)
          {
              for (int j = 0; j &lt; size; j++)
              {
                  cells[i, j] = new Cell { state = false, col = false };
                  Rectangle rect = new Rectangle();
                  Grid.SetColumn(rect, j);
                  Grid.SetRow(rect, i);
                  rect.Fill = Brushes.Orange;
                  rect.DataContext = cells[i, j];
                  rect.SetBinding(OpacityProperty, &quot;ev_opacity&quot;);
                  Binding binding = new Binding(&quot;ev_col&quot;);
                  binding.Converter = new BooleanToBrushConverter();
                  rect.SetBinding(Rectangle.FillProperty, binding);
                  main_grid.Children.Add(rect);
              }
          }
          setupTimer();
      }
  </code></pre>
  <p>How to set color of rectangle in dependency with col?
  (f.e: true - black, false - white)</p>
  <p>Cell class:</p>
  <pre><code>class Cell : INotifyPropertyChanged
      {
          private bool _state;
          private bool _Col;
          public event PropertyChangedEventHandler PropertyChanged;
          public event PropertyChangedEventHandler PropertyChanged2;
          public bool Col; //to set color
          {
              get
              {
                  return _Col;
              }
              set
              {
                  _Col = value;
                  if (PropertyChanged2 != null)
                  {
                      PropertyChanged2(this, new PropertyChangedEventArgs(&quot;event2&quot;));
                  };  
              }
          }
          public bool state //to set opacity
          {
              get
              {
                  return _state;
              }
              set
              {
                  _state = value;
                  if (PropertyChanged != null)
                  {
                      PropertyChanged(this, new PropertyChangedEventArgs(&quot;ev_opacity&quot;));
                  };
              }
          }
          public static implicit operator int(Komorka c)
          {
              return Convert.ToInt32(c.state);
          }
      }
  </code></pre>
  <p>Edit:
  This code does not work - after run nothing happen if I click on grid.</p>