adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
568 stars 47 forks source link

ContextActions on windows #118

Closed MattePozzy closed 1 year ago

MattePozzy commented 1 year ago

Hi, I'm using the Maui listview and on windows I need to add a ContextActions due to this issue.

I have tried to create a new ViewCell in MauiReactor but the properry ContextActions there isn't. I also tried this code, but the context menu doesn't appears.

  MauiControls.ViewCell vc = new();
  List<MauiControls.MenuItem> items = new() {
      new MauiControls.MenuItem { Text = "uno" },
      new MauiControls.MenuItem { Text = "due" },
      new MauiControls.MenuItem { Text = "tre" },
  };

  foreach (var menu in items)
  {
      vc.ContextActions.Add(menu);
  }

  VStack container = new() { Utility.IsPhone() ? ItemTemplatePhone(item) : ItemTemplateDefault(item) };
  return new ViewCell((x) => x = vc) { container };

Also tried this:

 VStack container = new() { Utility.IsPhone() ? ItemTemplatePhone(item) : ItemTemplateDefault(item) };

  MauiControls.ViewCell _vcRef = new();
  ViewCell myCell = new ViewCell((x) => _vcRef = x) { container };

  List<MauiControls.MenuItem> items = new() {
      new MauiControls.MenuItem { Text = "uno" },
      new MauiControls.MenuItem { Text = "due" },
      new MauiControls.MenuItem { Text = "tre" },
  };

  foreach (var menu in items)
  {
      _vcRef.ContextActions.Add(menu);
  }

How can I add a context menu to a ViewCell?

Thank you!

adospace commented 1 year ago

ContextMenu is not supported in MauiReactor right now, working on add it, I'll keep you updated on this task

adospace commented 1 year ago

Using the latest version:

  private ViewCell RenderGroup(GroupOfPerson person)
  {
      return new ViewCell
      {
          new Label(person.Initial)
          {
              new MenuFlyout
              {
                  new MenuFlyoutItem("MenuItem1")
                      .OnClicked(()=>OnClickMenuItem("MenuItem1")),
                  new MenuFlyoutItem("MenuItem2")
                      .OnClicked(()=>OnClickMenuItem("MenuItem2")),
                  new MenuFlyoutItem("MenuItem3")
                      .OnClicked(()=>OnClickMenuItem("MenuItem3")),
              }
          }
          .FontSize(14.0)
          .FontAttributes(MauiControls.FontAttributes.Bold)
          .Margin(5)
          .BackgroundColor(Colors.LightGray)
          ,
      };
  }

  private void OnClickMenuItem(string title)
  {
      ContainerPage?.DisplayAlert("MauiReactor", $"Clicked menu {title}", "OK");
  }