Reputation: 33
I have a problem with the DevExpress namely: Button in RibonControl. I wrote the event "click" for the way the button in RibonControl as follows:
private void barButtonClick_ItemClick(object sender, ItemClickEventArgs e)
{
BarButtonItem item = (BarButtonItem)(sender);
//..... if else ...
}
and I get an error message while running:
Additional information: Unable to cast object of type 'DevExpress.XtraBars.Ribbon.RibbonBarManager' to type 'DevExpress.XtraBars.BarButtonItem'.
I think, this error due to the fact that "click" of the button in DevExpress similar in WPF (routed events), correct? and how to solve?
Upvotes: 2
Views: 3536
Reputation: 17850
Here is how the correct code-snippet looks for your task:
void barButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
BarButtonItem bItem = e.Item as BarButtonItem;
// ... do something
}
Documentation: the ItemClickEventArgs.Item property.
The fact, that sender
parameter within this event handler is BarManager
rather than the BarButtonItem
, can be explained via DevExpress XtraBars Suite architecture.
The main idea is that the BarItem
is a non-visual element that can't be "clicked". The BarItemLink
element is a link to this item that represent item on screen. The BarManager
instance manage all the interactions with links and route all the events to the corresponding item's and BarManager's event handlers. That's why the BarManager/RibbonBarManager
instance appears as sender
parameter within the event handler.
See Items and Links for more details.
Upvotes: 2