How add MenuBar to Eto.Panel

Hi everyone,

I want to create MenuBar object for my plugin on the Panel.

    private void InitializeComponent()
    {
        tabControl = new TabControl()
		{
			TabPosition = DockPosition.Top,
		};

        menuBar = new MenuBar()
        {
            // some definitions
        }
    }

    private void InitializeLayout()
    {
		TableLayout tableLayout = new TableLayout()
		{
			Rows =
			{
                menuBar,
                ///////////------ Can not define menuBar here ------ /////////
				tabControl,
			}
		};
		Content = tableLayout;
	}

1. Why I cannot define menuBar in TableLayout?
2. How I can add MenuBar into Eto.Panel ?

Capture

Thanks in advance
-Oğuzhan

Menu is a property of a Window instance. Doesn’t look like you can assign it to a Panel or any layout class for that matter.
Some pseudo code:

var win = new Eto.Forms.Form()
win.Menu = new MenuBar(){...}
1 Like

Thanks for your answer,

Can we say that, it is not a good idea using panel plugins that will be packaged and licenced. Because it seems that I couldn’t add MenuBar for some options. What do you think?

Hey everyone,

Just to give a little background to the reasoning why you cannot use a menu bar in a panel or other container is because macOS does not support it. However, here are some alternatives you can experiment with:

  1. Show a ContextMenu when clicking on a Button
  2. Use the SegmentedButton with multiple MenuSegmentedItem items (this would get you closest to what you are looking for).

Hope this helps!

2 Likes

Hi @curtisw,

Thanks for clarify the topic, about structure I achieved what I want. I have extra question.

Why I cannot add MenuItemCollection on the ContextMenu ?
Its giving does not contain a constructor that takes 0 arguments error.

segmented

    MenuSegmentedItem fileSegmentedItem = new MenuSegmentedItem()
	{
		Text = "File",
		Menu = new ContextMenu()
		{
			Items =
			{
               ///////// ----- Cannot add here `MenuItemCollection` ----- //////// 
            },
		},
	};

	SegmentedButton segmentedButton = new SegmentedButton()
	{
		Items =
		{
			fileSegmentedItem,
			new MenuSegmentedItem()
			{
				Text = "Tools",
            },
			new MenuSegmentedItem()
			{
				Text = "Options",
			},
			new MenuSegmentedItem()
			{
				Text = "Help",
			},
		},
	};

Thanks,
-Oğuzhan

@oguzhankoral, you need to use one of the MenuItem subclasses (MenuItem is abstract).

For example:

var fileSegmentedItem = new MenuSegmentedItem()
{
	Text = "File",
	Menu = new ContextMenu()
	{
		Items =
		{
			new ButtonMenuItem { Text = "Hello" }
		},
	},
};
1 Like

@curtisw, It’s totally worked! Thanks a lot :slight_smile: