tech74
tech74

Reputation: 1659

Dotnet Maui MenuFlyout , how to bind to Collection

There is no ItemsSource property on the dotnet maui 7 ContextMenu MenuFlyout. How can we bind this to a collection. Surely they don't expect us to hardcode this? I'm trying to get a list of these within a MenuFlyoutSubItem

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/context-menu?view=net-maui-7.0

Thanks

Upvotes: 1

Views: 1245

Answers (1)

tech74
tech74

Reputation: 1659

Anyway we found a workaround, as we needed a dynamically generated context menu, we now use a TapGestureRecogniser to handle a right click event and then in the code behind create the whole context menu itself each time and attach it to the view.

void ContextMenu_Selected(System.Object sender,Microsoft.Maui.Controls.TappedEventArgs e)
{
    HorizontalStackLayout hs = (HorizontalStackLayout)sender;
    MenuFlyout mf = new MenuFlyout();
    MenuFlyoutItem flyoutItem = new MenuFlyoutItem();
    flyoutItem.Text = "Menu text"
    mf.Add(flyoutItem);
    FlyoutBase.SetContextFlyout(hs, mf);
}

Upvotes: 2

Related Questions