Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Act as contextmenu #66

Open
marcohgt opened this issue Jan 23, 2021 · 0 comments
Open

Act as contextmenu #66

marcohgt opened this issue Jan 23, 2021 · 0 comments

Comments

@marcohgt
Copy link

marcohgt commented Jan 23, 2021

One interesting feature could be the possibility to reuse RibbonItems as menu items in an extern context menu.
Some other controls in your application could need to show some context menu, where you expect to populate with some of the existing items from the ribbon.
The context menu would be raised up and you would have to create dynamically the context menu:

Ribbon _ribbon; // your main ribbon
RibbonDropDown _dropDown; // the dropdown context menu

public void ShowDropDown(Point screenCoordinates)
{
  // the function to invoke from your control context menu request callback
  List<RibbonItem> items;
  RibbonButton dummyButton;

  DisposeDropDown();  
  items = new List<RibbonItem>();
  dummyButton = new RibbonButton("");
  PopulateDropDown(items); // any function that takes care of creating/collecting the items from the ribbon
 // this ctor is only present in my temporary code
  _dropDown = new RibbonDropDown(dummyButton, items, _ribbon);
  _dropDown.Show(screenCoordinates);
}

public void PopulateDropDown(List<RibbonItem> items)
{
   RibbonButton btn;
   btn  = new RibbonButton("Test 1");
   btn .Click += RibbonButton_Click;
   items.Add(btn);
}

public void DisposeDropDown()
{
    if (_dropDown != null)
    {
        // if dropdown items were just created dynamically to be hosted in the context menu, we must dispose them

        foreach (RibbonItem oldItem in _dropDown.Items)
            oldItem.Click -= RibbonButton_Click;
        _dropDown.Dispose();
    }
}

Everything is already working: menu drawing is perfect in any point of the screen. The only thing is not working for me is that RibbonMouseSensor is not raising the MouseUp/MouseDown/Click and all the related events. But that's probably due to something strange I've not understood yet, because I have the same problems also with regular DropDownItems inside a regular RibbonButton in the main ribbon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant