Skip to content

Act as contextmenu #66

@marcohgt

Description

@marcohgt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions