Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ filtering in IEnumerable property breaks binding
    primarykey
    data
    text
    <p>I have a <code>TextBlock</code> in my UI bound to the <code>.Count()</code> extension of a property. I would like to add LINQ filtering to the property, but when I do it breaks the binding.</p> <p>This works and updates the UI without any problems:</p> <pre><code>public IEnumerable&lt;Worker&gt; WorkersTest { get { return DataManager.Data.Workers; } } </code></pre> <p>After adding LINQ filtering, <code>WorkersTest</code> does not update the <code>TextBlock</code>, though a MessageBox confirms that the property is being modified. Upon initialization of the data, however, the value displays correctly:</p> <pre><code>public IEnumerable&lt;Worker&gt; WorkersTest { get { return DataManager.Data.Workers.Where(w =&gt; w.Gender == Gender.Male); } } </code></pre> <p>Is there any way to keep the LINQ filtering without breaking the binding?</p> <p><strong>Update:</strong> One thing that I need to clarify is that <code>DataManager.Data.Workers</code> is an <code>ObservableCollection</code>.</p> <p>From what I can tell, any LINQ operation breaks the binding with the exception of <code>AsEnumerable()</code>, which doesn't have any effect.</p> <p>Also, in response to Andres' answer, <code>Count()</code> isn't the problem. If I bind this property to a <code>DataGrid</code>, I get the same results. With LINQ, it doesn't update. Without LINQ, it does. Is there any sort of workaround for this, preferably one that doesn't involve <code>ICollectionView</code> or anything of that nature?</p> <p><strong>Update:</strong> Does anybody know if LINQ extensions such as <code>Where</code> return new objects when used? I haven't been able to find any documentation of this online. If this is the case, however, that may be the problem.</p> <p><strong>Update:</strong> I inserted a breakpoint and found some interesting information that may be useful:</p> <p>Without LINQ:</p> <p><img src="https://i.stack.imgur.com/IMsEb.png" alt="enter image description here"></p> <p>With LINQ:</p> <p><img src="https://i.stack.imgur.com/nN29H.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/JkARU.png" alt="enter image description here"></p> <p>Perhaps this can shed some light on what's really going on and hopefully get me closer to the solution.</p> <p>Would I be correct in assuming that <code>CollectionChanged</code> and <code>PropertyChanged</code> being null is the source of the problem? If so, what can I do to fix that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload