Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
560
CustomButton in MenuTool
posted

Hello ...as shown in an example for the XamFeatureBrowser I created a CustomButton for the XamRibbon-Control.

The new CustomButton inherits Buttontool:

public partial class CustomRibbonButton : ButtonTool, IRibbonTool

and uses the following static constructor:

static CustomRibbonButton()
           {
RibbonGroup.MaximumSizeProperty.OverrideMetadata(typeof(CustomRibbonButton),new  FrameworkPropertyMetadata(RibbonToolSizingMode.ImageAndTextNormal));
           }

Inside the new Custom Control I want to react to the click event of the Custombutton itself. In order to achieve that I did something like that: 

protected override void OnClick()
   {
      base.OnClick();

           ...
   }

Everything is working as expected so far for a Button in the Ribbon or in the Qat. But when I add the CustomButton inside a Menutool Control I don't run in the OnClick Handler. Any help would be appreciated.

Parents
  • 54937
    Verified Answer
    Offline posted

    Tools like a ButtonTool are not actually displayed in a MenuTool. Instead the items of the menutool are hosted/contained within a ToolMenuItem. The command of the ToolMenuItem is bound and we also raise the click event of the associated tool (e..g. the ButtonTool) but we don't call the OnClick since for something like a ToggleButton that would result in other changes like toggling the value. You can override the OnMenuItemClick of the RibbonToolProxy you are using and do whatever you were doing in the Click event. Another option might be to hook your own Click event but be careful to only process it when the e.OriginalSource is that button tool instance since the event handlers will be copied when the tool is cloned for the qat, etc. (e.g. if (e.OriginalSource = sender) { // do your stuff here })

Reply Children