title: memory card game wpf problem
body: <p>I have a memorey card game where my binding is to</p>
  <pre><code>public ObservableCollection&lt;List&lt;memoryCard&gt;&gt; MyCollection { get; set; }//holding the array 
  </code></pre>
  <p>where is initlized like this :</p>
  <pre><code>for (int i = 0; i &lt; Size; i++)
          {
              List&lt;memoryCard&gt; list = new List&lt;memoryCard&gt;();
  
              for (int j = 0; j &lt; Size; j++)
              {
                  var card = new memoryCard(createRandomBrush(array, j));
                  card.IsChecked = false;
                  list.Add(card);
                  card.PropertyChanged += (a, b) =&gt; Verify(b.PropertyName);
              }
              MyCollection.Add(list);
          }
  **EDIT its now working except to the one EDIT in the middle who do me an hard time **
       private void Verify(string propName)
      {
          if (propName != &quot;IsChecked2&quot;)
          {
              return;
          }
  
         // List&lt;memoryCard&gt; selected = new List&lt;memoryCard&gt;();
          foreach (List&lt;memoryCard&gt; observerListItem in MyCollection)
              foreach (memoryCard mycard in observerListItem)
                  if (mycard.IsChecked == true)
                      selected.Add(mycard);
  
          if (selected.Count == 2)
          {
              if ((selected.First().buttonColor == selected.Last().buttonColor) &amp;&amp; 
                  (!selected.First().Equals(selected.Last()  )   )   )
              {
                  if (firstClick)
                  {
                      MessageBox.Show(&quot;Good.&quot;, &quot;Result&quot;, MessageBoxButton.OK, MessageBoxImage.Information);
                      firstClick = !firstClick;
   selected.ForEach(cell =&gt; cell.buttonColor = Brushes.White);
                      //here the biding color of the toggle item should chang and it doesnt can someone explain me how to do it right ?ite
                  }
  
                  }
              }
              else
              {
                  if (firstClick)
                  {
                      MessageBox.Show(&quot;Bad.&quot;, &quot;Result&quot;, MessageBoxButton.OK, MessageBoxImage.Error);
                      firstClick = !firstClick;
                  }
              }
              selected.First().IsChecked = selected.Last().IsChecked = false;
              selected.Clear();
              firstClick = true;
           
          }
  </code></pre>
  <p>if (selected.Count!=0)selected.First().IsChecked = false;
  }</p>
  <pre><code>and my memoreycard class is :
  
  
   public class memoryCard : INotifyPropertyChanged
  {
      #region c'tor
      public memoryCard(Brush _buttonColor)
      {
          buttonColor=_buttonColor;
      }
      #endregion
      private bool ?_isChecked = false;
      public bool ?IsChecked
      {
          get
          {
              return _isChecked;
          }
          set
          { 
              if (_isChecked != value)
              {
                  _isChecked = value;
                  //OnPropertyChanged(&quot;IsChecked&quot;);
                  OnPropertyChanged(&quot;IsChecked2&quot;);
              }
          }
      }
  
      #region colorofbutton
          
          public Brush buttonColor;
          public Brush ButtonColor
          {
              get
              {
                  return buttonColor;
              }
              set
              {
                  buttonColor = value;
              }
              
          }
          #endregion
  
      
      
      #region INotifyPropertyChanged Members
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          private void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
          #endregion
  }
  </code></pre>
  <p>}</p>
  <p>I try to achieve the goal of a memory card game
  check if there are two card who were IsCheck/ed property value = true and check there color if there's color is equal make this toggle button in a IsCheck/ed property null
  but the prior algoritam doesnt work!!</p>
  <p>this is an example fo what i am trying to achive by the end atoggle button who's changed according to the game
  <strong>EDIT</strong>
  how can I do it using the triggers when all the logic above is working ng ?...</p>
  <pre><code>&lt;ControlTemplate x:Key=&quot;ButtonControlTemplate1&quot; TargetType=&quot;{x:Type ToggleButton}&quot;&gt;
              &lt;Grid&gt;
                  &lt;Ellipse Name=&quot;elipse1&quot; Height=&quot;65&quot; Width=&quot;79&quot; Fill=&quot;{Binding Path=ButtonColor}&quot; Visibility=&quot;Collapsed&quot;&gt;&lt;/Ellipse&gt;
                  &lt;Ellipse Name=&quot;elipse2&quot; Height=&quot;65&quot; Width=&quot;79&quot; Fill=&quot;Black&quot; &gt;&lt;/Ellipse&gt;
              &lt;/Grid&gt;
              &lt;ControlTemplate.Triggers&gt;
                  &lt;Trigger Property=&quot;IsPressed&quot; Value=&quot;True&quot;&gt;
                      &lt;Setter TargetName=&quot;elipse1&quot; Property=&quot;Visibility&quot; Value=&quot;Visible&quot;/&gt;
                      &lt;Setter TargetName=&quot;elipse2&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
                  &lt;/Trigger&gt;
  
                  &lt;Trigger Property=&quot;IsCheck&quot; Value=&quot;null&quot;&gt;
                      &lt;Setter TargetName=&quot;elipse1&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
                      &lt;Setter TargetName=&quot;elipse2&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
                  &lt;/Trigger&gt;
  
                  
              &lt;/ControlTemplate.Triggers&gt;
          &lt;/ControlTemplate&gt;
  </code></pre>
  <p>**  EDIT**</p>
  <p>so to summrize i have two questiones about my code</p>
  <ol>
  <li><p>i changed the card color to white in verfy why doesnt the toggle button associted to him changes his color as well?</p>
  </li>
  <li><p>how can i trugger a toggle button to be allways in one color? when a card gets new color ,White i want him to change his color to ehite how can i achieve it ?</p>
  <p>thank you very much.</p>
  </li>
  </ol>
  <p><strong>EDIT2</strong></p>
  <p>my only problem is thatbindingto the color and changing the color like this :</p>
  <pre><code>     selected.ForEach(cell =&gt; cell.buttonColor = Brushes.White);
  </code></pre>
  <p>doesnt make the ui notice it , even thought the card property changed and call</p>
  <pre><code>  OnPropertyChanged(&quot;ButtonColor&quot;);
  </code></pre>
  <p>the UI doesnt change it</p>
  <p><strong>EDIT3</strong></p>
  <p>now i want a triger that whent i am on it will give aany toggle button who have white color the white color</p>
  <pre><code>       &lt;ControlTemplate x:Key=&quot;ButtonControlTemplate1&quot; TargetType=&quot;{x:Type ToggleButton}&quot;&gt;
              &lt;Grid&gt;
                  &lt;Ellipse Name=&quot;elipse1&quot; Height=&quot;65&quot; Width=&quot;79&quot; Fill=&quot;{Binding Path=ButtonColor}&quot; Visibility=&quot;Collapsed&quot;&gt;&lt;/Ellipse&gt;
                       &lt;Ellipse Name=&quot;elipse2&quot; Height=&quot;65&quot; Width=&quot;79&quot; Fill=&quot;Black&quot; &gt;&lt;/Ellipse&gt;
       &lt;Ellipse Name=&quot;elipse3&quot; Height=&quot;65&quot; Width=&quot;79&quot; Fill=&quot;Black&quot; Visibility=&quot;Collapsed&quot; &gt;&lt;/Ellipse&gt;
              &lt;/Grid&gt;
              &lt;ControlTemplate.Triggers&gt;
                  &lt;Trigger Property=&quot;IsPressed&quot; Value=&quot;True&quot;&gt;
                      &lt;Setter TargetName=&quot;elipse1&quot; Property=&quot;Visibility&quot; Value=&quot;Visible&quot;/&gt;
                      &lt;Setter TargetName=&quot;elipse2&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
                  &lt;/Trigger&gt;
  
                  &lt;Trigger Property=&quot;IsCheck&quot; Value=&quot;null&quot;&gt;
                      &lt;Setter TargetName=&quot;elipse1&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
                      &lt;Setter TargetName=&quot;elipse2&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot;/&gt;
          &lt;Setter TargetName=&quot;elipse3&quot; Property=&quot;Visibility&quot; Value=&quot;Visible&quot;/&gt;
  
                  &lt;/Trigger&gt;
  </code></pre>