amwx / FluentAvalonia

Control library focused on fluent design and bringing more WinUI controls into Avalonia
MIT License
1.05k stars 97 forks source link

NullReferenceException when trying to remove selected item in NavigationView 2.1.0-preview6 #588

Open OleRoss opened 5 months ago

OleRoss commented 5 months ago

Describe the bug Following bug 572, when I try to clear the items, I get a NullReferenceException.

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at FluentAvalonia.UI.Controls.NavigationView.RaiseItemInvoked(Object item, Boolean isSettings, NavigationViewItemBase container, NavigationRecommendedTransitionDirection recDir)
   at FluentAvalonia.UI.Controls.NavigationView.ChangeSelection(Object prevItem, Object nextItem)
   at FluentAvalonia.UI.Controls.NavigationView.OnSelectedItemPropertyChanged(Object oldItem, Object newItem)
   at FluentAvalonia.UI.Controls.NavigationView.OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.AvaloniaObject.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.Animation.Animatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)
   at Avalonia.AvaloniaObject.RaisePropertyChanged[T](AvaloniaProperty`1 property, Optional`1 oldValue, BindingValue`1 newValue, BindingPriority priority, Boolean isEffectiveValue)
   at Avalonia.AvaloniaObject.SetAndRaise[T](DirectPropertyBase`1 property, T& field, T value)
   at FluentAvalonia.UI.Controls.NavigationView.set_SelectedItem(Object value)
   at FluentAvalonia.UI.Controls.NavigationView.SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNotInvokedFromAPI(Object selItem)
   at FluentAvalonia.UI.Controls.NavigationView.OnSelectionModelSelectionChanged(Object sender, SelectionModelSelectionChangedEventArgs e)
   at FluentAvalonia.UI.Controls.SelectionModel.OnSelectionChanged()
   at FluentAvalonia.UI.Controls.SelectionModel.OnSelectionInvalidatedDueToCollectionChange()
   at FluentAvalonia.UI.Controls.SelectionNode.OnSourceListChanged(Object dataSource, NotifyCollectionChangedEventArgs args)
   at Avalonia.Controls.ItemsSourceView.Avalonia.Controls.Utils.ICollectionChangedListener.Changed(INotifyCollectionChanged sender, NotifyCollectionChangedEventArgs e)
   at Avalonia.Controls.Utils.CollectionChangedEventManager.Entry.<Avalonia.Utilities.IWeakEventSubscriber<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.OnEvent>g__Notify|6_0(INotifyCollectionChanged incc, NotifyCollectionChangedEventArgs args, WeakReference`1[] listeners)
   at Avalonia.Controls.Utils.CollectionChangedEventManager.Entry.Avalonia.Utilities.IWeakEventSubscriber<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.OnEvent(Object notifyCollectionChanged, WeakEvent ev, NotifyCollectionChangedEventArgs e)
   at Avalonia.Utilities.WeakEvent`2.Subscription.OnEvent(Object sender, TEventArgs eventArgs)
   at Avalonia.Utilities.WeakEvents.<>c__DisplayClass5_0.<.cctor>b__5(Object _, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at AvaloniaTests.ViewModels.MainWindowViewModel.Test() in C:\Users\OleRosskamp\RiderProjects\AvaloniaTests\AvaloniaTests\ViewModels\MainWindowViewModel.cs:line 16
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore()
   at Avalonia.Threading.DispatcherOperation.Execute()
   at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job)
   at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback)
   at Avalonia.Threading.Dispatcher.Signaled()
   at Avalonia.Win32.Win32DispatcherImpl.DispatchWorkItem()
   at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at AvaloniaTests.Program.Main(String[] args) in C:\Users\OleRosskamp\RiderProjects\AvaloniaTests\AvaloniaTests\Program.cs:line 13

Screenshots Minimal Repo: https://github.com/OleRoss/AvaloniaTests/tree/fe2bdf7f811452f934bf975e09f2cd06069a727a

The repo is the same as before, I just updated to preview6 and avalonia rc1. Steps to reproduce:

image

Desktop/Platform (please complete the following information):