From b8bbe291ad0e54893d4baac488ab779eabdbd1fd Mon Sep 17 00:00:00 2001 From: Felipe Baltazar Date: Sat, 16 Nov 2024 00:38:02 -0300 Subject: [PATCH] Update TabView.cs --- .../TabView.cs | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Maui.CommunityToolkit.TabView.Compat/TabView.cs b/Maui.CommunityToolkit.TabView.Compat/TabView.cs index 6abb988..40d3756 100644 --- a/Maui.CommunityToolkit.TabView.Compat/TabView.cs +++ b/Maui.CommunityToolkit.TabView.Compat/TabView.cs @@ -154,20 +154,38 @@ void DisableLoop() public void Dispose() { - if (contentContainer != null) + try { - contentContainer.PropertyChanged -= OnContentContainerPropertyChanged; - contentContainer.Scrolled -= OnContentContainerScrolled; + + if (contentContainer != null) + { + contentContainer.PropertyChanged -= OnContentContainerPropertyChanged; + contentContainer.Scrolled -= OnContentContainerScrolled; + } + } + catch (Exception _) { } + + try + { + if (tabItemsSource is INotifyCollectionChanged notifyTabItemsSource) + notifyTabItemsSource.CollectionChanged -= OnTabItemsSourceCollectionChanged; } + catch (Exception _) { } - if (tabItemsSource is INotifyCollectionChanged notifyTabItemsSource) - notifyTabItemsSource.CollectionChanged -= OnTabItemsSourceCollectionChanged; + try + { + if (TabItems != null) + TabItems.CollectionChanged -= OnTabItemsCollectionChanged; - if (TabItems != null) - TabItems.CollectionChanged -= OnTabItemsCollectionChanged; + } + catch (Exception _) { } - var lazyView = (contentContainer?.CurrentItem as TabViewItem)?.Content as BaseLazyView ?? TabItems?[SelectedIndex].Content as BaseLazyView; - lazyView?.Dispose(); + try + { + var lazyView = (contentContainer?.CurrentItem as TabViewItem)?.Content as BaseLazyView ?? TabItems?[SelectedIndex].Content as BaseLazyView; + lazyView?.Dispose(); + } + catch (Exception _) { } } public ObservableCollection TabItems { get; set; }