XF-Material-Library icon indicating copy to clipboard operation
XF-Material-Library copied to clipboard

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

Open divyesh008 opened this issue 2 years ago • 4 comments

🐛 Bug Report

Expected behavior

  • It should work properly and show a popup with menu items.

Reproduction steps

  • Add MaterialMenuButton on the page and when clicking on the button it crashes the app.

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

  • Visual Studio for Mac 2022 Version 17.0.1 (build 72)

Version: 1.x

  • XF.Material - 1.8.0

Platform:

  • [x] :iphone: iOS
  • [x] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms

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 

divyesh008 avatar Jun 22 '22 16:06 divyesh008

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

hpposch avatar Jul 08 '22 10:07 hpposch

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

divyesh008 avatar Jul 08 '22 15:07 divyesh008

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)

hpposch avatar Jul 09 '22 08:07 hpposch

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.

divyesh008 avatar Jul 09 '22 10:07 divyesh008