I have a virtualizing ListView control with a user control as the items template. When the user control is loaded an async call is made that I'd like to cancel if the user control is out of view.
I tried using Unloaded but this is not called, even though the items stack panel's cache no longer contains that item. What event will notify the C# when a user control leaves the item stack panels cache, or list view's viewable area?
I tried using container content changing but it only shows which items are coming into view, but does not show when the container items leaves view.
Thank you :)
Here is the XAML.
<ListView ItemsSource="{Binding MyItemsObs}"
ContainerContentChanging="ListViewBase_OnContainerContentChanging"
Loaded="ListView_OnLoaded"
Style="{StaticResource ListViewStyle1}">
<ListView.ItemTemplate>
<DataTemplate>
<local:MyItemUC/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You can get the items stack panel by adding a loaded event in the listview template, or use some visual tree helper extension like win rt xaml toolkit.
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
_itemsStackPanel = sender as ItemsStackPanel;
_itemsStackPanel.CacheLength = 0;
}