Baseflow / XF-Material-Library

A Xamarin Forms library for implementing Material Design
https://baseflow.com
MIT License
647 stars 161 forks source link

MaterialMenuButton - on click application got crash in both Android and iOS #449

Open divyesh008 opened 2 years ago

divyesh008 commented 2 years ago

🐛 Bug Report

Expected behavior

Reproduction steps

MainPage.xaml

<material:MaterialMenuButton
            Grid.Row="0" Grid.Column="1"
            ButtonType="Elevated"
            Image="dots_circle"
            HorizontalOptions="End"
            HeightRequest="45"
            WidthRequest="45"
            Choices="{Binding Actions}"
            Command="{Binding ActionSelectCommand}"
            BackgroundColor="Transparent"/>

MainPageViewModel.cs

public MainPageViewModel()
{
      ObservableCollection<MaterialMenuItem> actions = new ObservableCollection<MaterialMenuItem>();
      actions.Add(new MaterialMenuItem() { Text = "Details" });
      actions.Add(new MaterialMenuItem() { Text = "Edit" });
      actions.Add(new MaterialMenuItem() { Text = "Upload Document" });
      actions.Add(new MaterialMenuItem() { Text = "Add Project" });
      Actions = new ObservableCollection<MaterialMenuItem>(actions);
}

private ObservableCollection<MaterialMenuItem> _actions { get; set; }
public ObservableCollection<MaterialMenuItem> Actions
{
     get => _actions;
     set { _actions = value; OnPropertyChanged(nameof(Actions)); }
}

Configuration

Version: 1.x

Platform:

Exception Message: Cannot show menu, property Choices is null or has no items

Stack Trace


at XF.Material.Forms.UI.MaterialMenuButton.OnViewTouch (System.Double x, System.Double y) [0x0002c] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\MaterialMenuButton.cs:131 
at XF.Material.iOS.Renderers.MaterialMenuRenderer.OnClick () [0x0001b] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\Platforms\Ios\Renderers\MaterialMenuRenderer.cs:26 
at Xamarin.Forms.Command+<>c__DisplayClass4_0.<.ctor>b__0 (System.Object o) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:74 
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:112 
at XF.Material.Forms.UI.MaterialIconButton.OnButtonClicked (System.Boolean handled) [0x00017] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\MaterialIconButton.xaml.cs:145 
at XF.Material.Forms.UI.MaterialMenuButton.OnButtonClicked (System.Boolean handled) [0x00000] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\MaterialMenuButton.cs:120 
at XF.Material.Forms.UI.MaterialIconButton.<.ctor>b__13_0 () [0x00000] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\MaterialIconButton.xaml.cs:47 
at Xamarin.Forms.Command+<>c__DisplayClass4_0.<.ctor>b__0 (System.Object o) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:74 
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:112 
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x00008] in D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:60 
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:173 
at Xamarin.Forms.Platform.iOS.ButtonElementManager.OnButtonTouchUpInside (Xamarin.Forms.IButtonController element) [0x00009] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonElementManager.cs:86 
at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ButtonRenderer.cs:189 
at UIKit.UIControlEventProxy.Activated () [0x00004] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIControl.cs:38 
--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:75 at solarcrm.Application.Main (System.String[] args) [0x0001b] in /Users/divyeshbhatt/Documents/sourcetree/APS/src/solarcrm.Mobile.iOS/Main.cs:20

hpposch commented 2 years ago

Hi I currently have the exact same issue. Any idea why this happens?

divyesh008 commented 2 years ago

I have recently used this control in my project and it's working fine in Xamarin Forms 5.0.0.2244

hpposch commented 2 years ago

Thanks for your answer, sadly it did not change anything. No matter which version of Xamarin.Fomrs i use. The strange thing is, that it works in some situation and in some it does not work. I can not really determine whats the problem, the data that gets provided is always the same (List)

divyesh008 commented 2 years ago

Yes, the best way to deal with this issue is either to use paid 3rd party libraries like Syncfusion, or Telerik or else use Picker control.