maui icon indicating copy to clipboard operation
maui copied to clipboard

Flyout is not refreshing when item visibility is changed

Open gktval opened this issue 3 years ago • 2 comments

Description

When changing the visibility of menu items in the Shell's Flyout, the flyout view is not updating. I have tried it in various ways, such as changing the FlyoutItemIsVisible property, the IsVisible property, and different views.

Steps to Reproduce

In the attached repository, there are two header items in the flyout:

  1. The first header item sets the visibility of the sub item with resources. The sub item will disappear from the flyout on visibility set to false, but the item will not reappear in the flyout when visibility is set to true.

  2. The second header should show the sub item when FlyoutItemIsVisible = true, but the results show that the flyout is not being updated, even with ForceLayout and InvalidateMeasure.

Link to public reproduction project repository

https://github.com/gktval/MauiAppShellFlyout

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

No

Relevant log output

none

gktval avatar Oct 03 '22 19:10 gktval

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Oct 04 '22 18:10 ghost

For me, now not only is the Flyout not refreshing, but my app crashes when a Flyout changes visibility. It's either a null exception or an index out of range exception when MAUI tries to update the visible Flyouts.

I just bind the visibility to some bool value to hit the bug:

image

Now I have to redesign my whole app to always have a static list of flyouts :(

spadapet avatar Mar 09 '23 23:03 spadapet

We cannot access the repo https://github.com/gktval/MauiAppShellFlyout

Result: Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0 using another maui-samples/7.0/Navigation/ShellFlyoutSample at main · dotnet/maui-samples · GitHub repo. Can repro on android platform, seems not repro on macOS (MyMac). Not sure if it is correct result, if not, please help correct me.

jinxinjuan avatar Jul 13 '23 03:07 jinxinjuan

Sorry about that. It is changed to public now. It should be a problem in windows as well.

gktval avatar Jul 13 '23 23:07 gktval

@BretJohnson, here are two test apps for hitting two different exceptions when flyouts change visibility:

The only difference in the two projects is the default value of ViewModel.ShowStuff

REPRO:

  • Open either solution
  • F5 to build and run on Windows
  • Click the one button that appears in the running app UI

RESULT: One of two exceptions, depending on which project was opened. You can change the reference to MAUI controls to a locally built package folder in order to debug

Callstack for ArgumentOutOfRangeException:

System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|20_0(int hr)
WinRT.Runtime.dll!ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.NativeDelegateWrapper.Invoke(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<object>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ShellView.UpdateMenuItemSource()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapFlyoutItems(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Shell, Microsoft.Maui.Controls.Handlers.ShellHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView, string property)
Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.UpdateValue(string property)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Shell..ctor.AnonymousMethod__154_2(object _, System.EventArgs __)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellFlyoutItemsManager.CheckIfFlyoutItemsChanged()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Shell.SendFlyoutItemsChanged()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellSection.SendStructureChanged()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellSection..ctor.AnonymousMethod__42_0(object _, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellContent>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.Remove(Microsoft.Maui.Controls.ShellContent item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.BaseShellItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BaseShellItem.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueActual(Microsoft.Maui.Controls.BindableProperty property, Microsoft.Maui.Controls.BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.SetterSpecificity specificity, bool silent)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueCore(Microsoft.Maui.Controls.BindableProperty property, object value, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.BindableObject.SetValuePrivateFlags privateAttributes, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.ApplyCore(object sourceObject, Microsoft.Maui.Controls.BindableObject target, Microsoft.Maui.Controls.BindableProperty property, bool fromTarget, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.Apply(bool fromTarget)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged.AnonymousMethod__50_0()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(Microsoft.Maui.Dispatching.IDispatcher dispatcher, System.Action action)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
>	MauiApp4.dll!MauiApp4.ViewModel.ShowStuff.set(bool value) Line 19
MauiApp4.dll!MauiApp4.MainPage.OnCounterClicked(object sender, System.EventArgs e) Line 14
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked()

Callstack for NullReferenceException:

Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Routing.GetRoute(Microsoft.Maui.Controls.BindableObject obj)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Routing.IsImplicit(Microsoft.Maui.Controls.BindableObject source)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(Microsoft.Maui.Controls.ShellItem newItem, bool animate)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Shell, Microsoft.Maui.Controls.Handlers.ShellHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView, string property)
Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.UpdateValue(string property)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Handlers.ShellHandler.MapItems(Microsoft.Maui.Controls.Handlers.ShellHandler handler, Microsoft.Maui.Controls.Shell view)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Shell, Microsoft.Maui.Controls.Handlers.ShellHandler>.Add.AnonymousMethod__0(Microsoft.Maui.IElementHandler h, Microsoft.Maui.IElement v)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdatePropertyCore(string key, Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView)
Microsoft.Maui.dll!Microsoft.Maui.PropertyMapper.UpdateProperty(Microsoft.Maui.IElementHandler viewHandler, Microsoft.Maui.IElement virtualView, string property)
Microsoft.Maui.dll!Microsoft.Maui.Handlers.ElementHandler.UpdateValue(string property)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Shell..ctor.AnonymousMethod__154_3(object _, System.Collections.Specialized.NotifyCollectionChangedEventArgs __)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellItem>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellItem>.Remove(Microsoft.Maui.Controls.ShellItem item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellItem>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnShellElementControllerItemsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellSection>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellSection>.Remove(Microsoft.Maui.Controls.ShellSection item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellSection>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnShellElementControllerItemsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.OnVisibleItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.ShellContent>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.Remove(Microsoft.Maui.Controls.ShellContent item)
System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection<Microsoft.Maui.Controls.ShellContent>.System.Collections.IList.Remove(object value)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.CheckVisibility(Microsoft.Maui.Controls.BaseShellItem element)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ShellElementCollection.BaseShellItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Element.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BaseShellItem.OnPropertyChanged(string propertyName)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueActual(Microsoft.Maui.Controls.BindableProperty property, Microsoft.Maui.Controls.BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.SetterSpecificity specificity, bool silent)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindableObject.SetValueCore(Microsoft.Maui.Controls.BindableProperty property, object value, Microsoft.Maui.Controls.Internals.SetValueFlags attributes, Microsoft.Maui.Controls.BindableObject.SetValuePrivateFlags privateAttributes, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.ApplyCore(object sourceObject, Microsoft.Maui.Controls.BindableObject target, Microsoft.Maui.Controls.BindableProperty property, bool fromTarget, Microsoft.Maui.Controls.SetterSpecificity specificity)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.Apply(bool fromTarget)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged.AnonymousMethod__50_0()
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(Microsoft.Maui.Dispatching.IDispatcher dispatcher, System.Action action)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args)
Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
>	MauiApp4.dll!MauiApp4.ViewModel.ShowStuff.set(bool value) Line 18
MauiApp4.dll!MauiApp4.MainPage.OnCounterClicked(object sender, System.EventArgs e) Line 14

spadapet avatar Aug 18 '23 18:08 spadapet

@spadapet - I split out the WinUI crashes to separate bugs, here: https://github.com/dotnet/maui/issues/16929 and https://github.com/dotnet/maui/issues/16940.

BretJohnson avatar Aug 22 '23 18:08 BretJohnson

Keeping this issue open for now

It looks like the visibility of the SubItem 2 is fixed but the visibility on the first "sub item" still doesn't return after being set back to visible.

Reproduction

  • Run attached repro
  • click "Header Item" => sub item disappears
  • click "Header Item" => sub item should now re-appear

PureWeen avatar Aug 24 '23 21:08 PureWeen

https://github.com/dotnet/maui/issues/16991

PureWeen avatar Aug 24 '23 22:08 PureWeen