11namespace Maui . Controls . Sample . Issues ;
22
33[ Issue ( IssueTracker . Github , 20685 , "MenuBarItem Commands not working on Mac Catalyst" ,
4- PlatformAffected . All ) ]
4+ PlatformAffected . All ) ]
55public class Issue20685 : TestShell
66{
7- protected override void Init ( )
8- {
9- var resultLabel = new Label
10- {
11- Text = "No action performed yet" ,
12- FontSize = 18 ,
13- HorizontalOptions = LayoutOptions . Center ,
14- AutomationId = "ResultLabel"
15- } ;
7+ protected override void Init ( )
8+ {
9+ var resultLabel = new Label
10+ {
11+ Text = "No action performed yet" ,
12+ FontSize = 18 ,
13+ HorizontalOptions = LayoutOptions . Center ,
14+ AutomationId = "ResultLabel"
15+ } ;
1616
17- var menuItems = new MenuBarItem { Text = "MenuItems" } ;
18-
17+ var menuItems = new MenuBarItem { Text = "MenuItems" } ;
1918
20- // 1. Menu item using Clicked event
21- var clickedItem = new MenuFlyoutItem
22- {
23- Text = "Test Clicked Event" ,
24- AutomationId = "ClickedEventItem"
25- } ;
26- clickedItem . Clicked += ( s , e ) => resultLabel . Text = "Clicked event handler executed" ;
27- menuItems . Add ( clickedItem ) ;
2819
29- // 2 . Menu item using Command
30- var commandItem = new MenuFlyoutItem
31- {
32- Text = "Test Command " ,
33- AutomationId = "CommandItem" ,
34- Command = new Command ( ( ) => resultLabel . Text = "Command executed" )
35- } ;
36- menuItems . Add ( commandItem ) ;
20+ // 1 . Menu item using Clicked event
21+ var clickedItem = new MenuFlyoutItem
22+ {
23+ Text = "Test Clicked Event " ,
24+ AutomationId = "ClickedEventItem"
25+ } ;
26+ clickedItem . Clicked += ( s , e ) => resultLabel . Text = "Clicked event handler executed" ;
27+ menuItems . Add ( clickedItem ) ;
3728
38- // 3. Menu item using Command with parameter
39- var parameterItem = new MenuFlyoutItem
40- {
41- Text = "Test Command Parameter" ,
42- AutomationId = "CommandWithParamItem" ,
43- Command = new Command < string > ( param => resultLabel . Text = $ "Command executed with parameter: { param } ") ,
44- CommandParameter = "Test Parameter"
45- } ;
46- menuItems . Add ( parameterItem ) ;
29+ // 2. Menu item using Command
30+ var commandItem = new MenuFlyoutItem
31+ {
32+ Text = "Test Command" ,
33+ AutomationId = "CommandItem" ,
34+ Command = new Command ( ( ) => resultLabel . Text = "Command executed" )
35+ } ;
36+ menuItems . Add ( commandItem ) ;
4737
48- MenuBarItems . Add ( menuItems ) ;
38+ // 3. Menu item using Command with parameter
39+ var parameterItem = new MenuFlyoutItem
40+ {
41+ Text = "Test Command Parameter" ,
42+ AutomationId = "CommandWithParamItem" ,
43+ Command = new Command < string > ( param => resultLabel . Text = $ "Command executed with parameter: { param } ") ,
44+ CommandParameter = "Test Parameter"
45+ } ;
46+ menuItems . Add ( parameterItem ) ;
4947
50- var contentPage = new ContentPage
51- {
52- Content = new VerticalStackLayout
53- {
54- Padding = new Thickness ( 20 ) ,
55- Spacing = 20 ,
56- HorizontalOptions = LayoutOptions . Fill ,
57- VerticalOptions = LayoutOptions . Center ,
58- Children =
59- {
60- new Label
61- {
62- Text = "MenuFlyoutItem Test" ,
63- FontSize = 24 ,
64- HorizontalOptions = LayoutOptions . Center
65- } ,
66- resultLabel ,
67- new Label
68- {
69- Text = "Use the menu bar at the top to test the commands" ,
70- HorizontalOptions = LayoutOptions . Center ,
71- HorizontalTextAlignment = TextAlignment . Center
72- }
73- }
74- }
75- } ;
48+ MenuBarItems . Add ( menuItems ) ;
7649
77- AddContentPage ( contentPage ) ;
78- }
50+ var contentPage = new ContentPage
51+ {
52+ Content = new VerticalStackLayout
53+ {
54+ Padding = new Thickness ( 20 ) ,
55+ Spacing = 20 ,
56+ HorizontalOptions = LayoutOptions . Fill ,
57+ VerticalOptions = LayoutOptions . Center ,
58+ Children =
59+ {
60+ new Label
61+ {
62+ Text = "MenuFlyoutItem Test" ,
63+ FontSize = 24 ,
64+ HorizontalOptions = LayoutOptions . Center
65+ } ,
66+ resultLabel ,
67+ new Label
68+ {
69+ Text = "Use the menu bar at the top to test the commands" ,
70+ HorizontalOptions = LayoutOptions . Center ,
71+ HorizontalTextAlignment = TextAlignment . Center
72+ }
73+ }
74+ }
75+ } ;
76+
77+ AddContentPage ( contentPage ) ;
78+ }
7979}
0 commit comments