Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Fade-out is likely to be impossible without re-writing the <code>ItemsControl</code> base implementation. The problem is that when the <code>ItemsControl</code> receives the <code>INotifyCollectionChanged</code> event from the collection it immediately (and within deep private code) marks the item container as not visible (<code>IsVisible</code> is a readonly property that gets its value from a hidden cache so cannot be accessed).</p> <p>You can easily implement the fade-in in this way:</p> <pre><code>public class FadingListBox : ListBox { protected override void PrepareContainerForItemOverride( DependencyObject element, object item) { var lb = (ListBoxItem)element; DoubleAnimation anm = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(500)); lb.BeginAnimation(OpacityProperty, anm); base.PrepareContainerForItemOverride(element, item); } } </code></pre> <p>But the 'fade-out' equivalent never works as the container is already invisible and cannot be reset.</p> <pre><code>public class FadingListBox : ListBox { protected override void ClearContainerForItemOverride( DependencyObject element, object item) { var lb = (ListBoxItem) element; lb.BringIntoView(); DoubleAnimation anm = new DoubleAnimation( 1, 0, TimeSpan.FromMilliseconds(500)); lb.BeginAnimation(OpacityProperty, anm); base.ClearContainerForItemOverride(element, item); } } </code></pre> <p>Even if you have your own custom container generator, you cannot overcome this issue</p> <pre><code>protected override DependencyObject GetContainerForItemOverride() { return new FadingListBoxItem(); } </code></pre> <p>And this kind of makes sense, because if the container was still visible after the data it represents has disappeared, then you could theoretically click on the container (kicking off triggers, events etc) and experience some subtle bugs perhaps.</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