title: Why does yield return in a property getter break WPF bindings?
body: <p>I have a property that performs a yield return in its get function:</p>
  
  <p>Data:</p>
  
  <pre><code>public class TestSummary
  {
     [Description("Test1")]
     public TestResult Test1 {get; set;}
  
     [Description("Test2")]
     public TestResult Test2 {get; set;}
  }
  public enum TestResult
  {
     Failed,
     Passed
  }
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>private TestSummary TestResults
  {
    get { return new TestSummary() { Test1=Failed, Test2=Passed }; }
  }
  public int TimePassed
  {
     get
     {
         return 2;
     }
  }
  
  public IEnumerable&lt;String&gt; FailedTests
  {
     get
     {
        PropertyDescriptorCollection attributes = TypeDescriptor.GetProperties(TestResults);
       foreach (PropertyInfo failedResult in typeof(TestSummary).GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                .Where(p =&gt; p.PropertyType == typeof(TestResult)).Where(t =&gt; (TestResult)t.GetValue(TestResults) == TestResult.Failed))
       {
          yield return ((DescriptionAttribute)attributes[failedResult.Name].Attributes[typeof(DescriptionAttribute)]).Description;
       }
     }
  }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;UserControl&gt;
  &lt;UserControl.DataContext&gt;
     &lt;local:ViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
     &lt;StackPanel&gt;
         &lt;ItemsControl ItemsSource="{Binding FailedTests}"/&gt;
         &lt;ProgressBar Value="{Binding TimePassed}"/&gt;
     &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Works and compiles just fine (the property is of type IEnumerable). You can even bind to it, and the UI updates correctly. However, having this code breaks other (seemingly random) bindings on other controls, even bindings internal to other user controls.</p>
  
  <p>My question is, why? This is perfectly valid C# and if anything it should break the bound UI control, not others.</p>
  
  <p><strong>Update</strong>
  Updated source code to be more complete. When I used the above, the getter for "TimePassed" was never called and the progress bar's Value was always 0.</p>
  
  <p>If it helps, using the same yield return in a function, calling it and assigning the result.ToList() to the property doesn't break anything. I am still curious as to why the posted code is causing the "TimePassed" binding to fail (getter is never called).</p>
  
  <p>Also interesting is that if I use Snoop to investigate the binding, the getter DOES get called when I try to look at the "broken" element.</p>