Note that there are some explanatory texts on larger screens.

plurals
  1. POListbox isn't showing my first item
    text
    copied!<p>I'm having a small problem with WPF and binding my listbox/listview to a custom list.</p> <p>This list has the IEnumerator &amp; IEnumerable interfaces implemented. If I bind my control to those, I never get to see the first object of that list.</p> <p>When I a gridview, it does show my first object. So for some reason the listbox/listview are doing different things to enumerate my custom list.</p> <p>My binding is for both setup the exact same way, using a public property on my ViewModel.</p> <p>The Binding ( My PersonObject has a public property ProjectList, which gets the custom list i'm talking about ).</p> <pre><code> public Person Person { get { return this._person; } set { if (this._person != value) { this._person = value; RaisePropertyChanged("Person"); } } } </code></pre> <p>The XAML:</p> <pre><code>&lt;ListBox ItemsSource="{Binding Path=Person.ProjectList,UpdateSourceTrigger=PropertyChanged}" AlternationCount="2" ItemContainerStyle="{StaticResource CustomListBoxItemStyle}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock&gt; &lt;TextBlock.Text&gt; &lt;MultiBinding StringFormat="{}{0} - {1}"&gt; &lt;Binding Path="Name" /&gt; &lt;Binding Path="Number" /&gt; &lt;/MultiBinding&gt; &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; &lt;TextBlock&gt; &lt;TextBlock.Text&gt; &lt;MultiBinding StringFormat="{}{0} - {1}"&gt; &lt;Binding Path="StartDate" /&gt; &lt;Binding Path="EndDate" /&gt; &lt;/MultiBinding&gt; &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>The Customlist class:</p> <pre><code>public class ProjectList : DeletableSupport, IEnumerator, IEnumerable { private IList&lt;Project&gt; _pList; private int _position; public ProjectList() { this._pList = new ActivatableList&lt;Project&gt;(); this._position = -1; } public void Add(Project p) { Activate(ActivationPurpose.Write); this._pList.Add(p); } public void Remove(Project p) { Activate(ActivationPurpose.Write); this._pList.Remove(p); } public int Count() { Activate(ActivationPurpose.Read); return this._pList.Count(); } public bool Contains(Project p) { Activate(ActivationPurpose.Read); return this._pList.Contains(p); } public Project this[int i] { get { Activate(ActivationPurpose.Read); return this._pList[i]; } set { Activate(ActivationPurpose.Write); this._pList[i] = value; } } public static ProjectList operator +(ProjectList pList, Project p) { pList.Add(p); return pList; } public static ProjectList operator -(ProjectList pList, Project p) { pList.Remove(p); return pList; } #region IEnumerable Members public IEnumerator GetEnumerator() { Activate(ActivationPurpose.Read); return (IEnumerator)this; } #endregion #region IEnumerator Members public object Current { get { try { Activate(ActivationPurpose.Read); return this._pList[_position]; } catch (IndexOutOfRangeException) { throw new InvalidOperationException(); } } } public bool MoveNext() { Activate(ActivationPurpose.Read); this._position++; if (_position &lt; this._pList.Count) { return true; } else { return false; } } public void Reset() { Activate(ActivationPurpose.Write); _position = -1; } #endregion } </code></pre> <p>The Activate is from db4o, the ActivatableList implements IList</p>
 

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