protected override void OnElementChanged(ElementChangedEventArgs <ListView> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.ItemSelected -= OnElementItemSelected; e.OldElement.ScrollToRequested -= OnElementScrollToRequested; ((ITemplatedItemsView <Cell>)e.OldElement).TemplatedItems.CollectionChanged -= OnCollectionChanged; if (Control != null) { Control.Loaded -= ControlOnLoaded; } } if (e.NewElement != null) { e.NewElement.ItemSelected += OnElementItemSelected; e.NewElement.ScrollToRequested += OnElementScrollToRequested; ((ITemplatedItemsView <Cell>)e.NewElement).TemplatedItems.CollectionChanged += OnCollectionChanged; if (List == null) { List = new ListViewTransparent(this) { IsSynchronizedWithCurrentItem = false, ItemTemplate = (Microsoft.UI.Xaml.DataTemplate)WApp.Current.Resources["CellTemplate"], HeaderTemplate = (Microsoft.UI.Xaml.DataTemplate)WApp.Current.Resources["View"], FooterTemplate = (Microsoft.UI.Xaml.DataTemplate)WApp.Current.Resources["View"], ItemContainerStyle = (Microsoft.UI.Xaml.Style)WApp.Current.Resources["MauiListViewItem"], GroupStyleSelector = (GroupStyleSelector)WApp.Current.Resources["ListViewGroupSelector"] }; List.SelectionChanged += OnControlSelectionChanged; SetNativeControl(List); } ReloadData(); UpdateGrouping(); UpdateHeader(); UpdateFooter(); UpdateSelectionMode(); UpdateWindowsSpecificSelectionMode(); ClearSizeEstimate(); UpdateVerticalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility(); if (Control != null) { Control.Loaded += ControlOnLoaded; } } }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { if (List != null) { foreach (ViewToHandlerConverter.WrapperControl wrapperControl in FindDescendants <ViewToHandlerConverter.WrapperControl>(List)) { wrapperControl.CleanUp(); } if (_subscribedToTapped) { _subscribedToTapped = false; List.Tapped -= ListOnTapped; } if (_subscribedToItemClick) { _subscribedToItemClick = false; List.ItemClick -= OnListItemClicked; } List.SelectionChanged -= OnControlSelectionChanged; if (_collectionViewSource != null) { _collectionViewSource.Source = null; } List.DataContext = null; // Leaving this here as a warning because setting this to null causes // an AccessViolationException if you run Issue1975 // List.ItemsSource = null; List = null; } if (_zoom != null) { _zoom.ViewChangeCompleted -= OnViewChangeCompleted; _zoom = null; } } base.Dispose(disposing); }