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.
Now everything is working as expected.
I was using a false Toolproxy in for my CustomButton in my last post. (Had to clarify the exact namespace)
Thanks a lot for your help.
Hello rmrop,
Please have a look at the attached sample where I show you how you can handle the Click when your Custom button is placed in RibbonGroup and how you can handle the OnMenuItemClick on the RibbonToolProxy in case you want to use your custom button in MenuTool as Andrew suggested.
If you need any further assistance on this, I will be glad to help.
Hello Andrew. Thanks for your help.
I would like to take the first option. Unfortunately my implementation seems not to work. At the moment the RibbonProxy looks like that:
public partial class ButtonToolProxy : RibbonToolProxy<vcRibbonButton> { public ButtonToolProxy(): base() { } protected override void OnMenuItemClick(vcRibbonButton tool) { base.OnMenuItemClick(tool); MessageBox.Show("Show Something"); } }
And the Implementation in the CustomControl:
public Infragistics.Windows.Ribbon.Internal.RibbonToolProxy ToolProxy { get { return new ButtonToolProxy(); } }
Is there something I forgot at this point ??
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 })