RibbonDropDownItem for click listening

I am developing a powerpoint addin and using the ribbon constructor for this. I have a gallery element containing RibbonDropDownItems . I can’t find a way to add clicks to listen there because the RibbonDropDownItem Interface does not have a 'Click' event, for example RibbonButton Interface .

So, is there a way to catch the click event from the RibbonDropDownItem object?


EDIT : Implementing add-ons for the office 2013-2016.

+4
source share
2 answers

SelectionChanged RibbonDropDown. , . , SelectionChanged , , :

  • , .
  • .
  • SelectedItem SelectedItemIndex .

, Fluent UI MSDN:

+1

, XML-.

RibbonGallery ( RibbonDropDownItems) click, ", ".

, RibbonGallery, , , RibbonGallery # SelectedItem. :

private void myDropdownGallery_Click(object sender, RibbonControlEventArgs e)
{
    //'ribbonGalleryObject' is the object created in Ribbon.Designer.cs
    RibbonDropDownItem item = ribbonGalleryObject.SelectedItem;

    string itemLabel = item.Label;

    if (itemLabel == "myItem1") {
        System.Windows.Forms.MessageBox.Show("Item 1 says hello");
    }
    else if (itemLabel == "myItem2"){
        System.Windows.Forms.MessageBox.Show("Item 2 says hello");
    }
}

, , RibbonDropDownItems .

private void gallery1_Click(object sender, RibbonControlEventArgs e)
{
    //'ribbonGalleryObject' is the object created in Ribbon.Designer.cs
    RibbonDropDownItem item = ribbonGalleryObject.SelectedItem;

    string itemLabel = item.Label;
    string methodName = itemLabel + "_Click";

    System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName);
    methodInfo.Invoke(this, null);
}

//click event handler for item 1
public void myItem1_Click()
{
    System.Windows.Forms.MessageBox.Show("Item 1 says hello");
}

//click event handler for item 2
public void myItem2_Click()
{
    System.Windows.Forms.MessageBox.Show("Item 2 says hello");
}

, , "" .

0

Source: https://habr.com/ru/post/1650442/


All Articles