4

As you can see in that screenshot in "objArgs" there is a property "Text". How can I reach that property?

enter image description here

Bayern
  • 330
  • 3
  • 20

1 Answers1

9

You need to cast the args to ToolBarItemEventArgs, at which point you can access the ToolBarButton it refers to:

var toolBarArgs = (ToolBarItemEventArgs) objArgs;
switch (toolBarArgs.ToolBarButton.Text)
{
    ...
}

However, I would suggest not switching on the text. Instead, ideally set up a different event handler for each of your buttons. If you really can't do that, you can use:

var toolBarArgs = (ToolBarItemEventArgs) objArgs;
var button = toolBarArgs.ToolBarButton;
if (button == saveButton)
{
    ...
}

Or you could switch on the Name rather than the Text - I'd expect the Name to be basically an implementation detail, whereas the Text is user-facing and could well be localized.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194