Unwanted execution of parent menu item

Topics: Actions & Coroutines
Nov 3, 2011 at 10:30 PM

I generate my menus using bindings to MenuModels. I'm having trouble with a click event on sub-MenuItems...


<Setter Property="Icon" Value="{StaticResource menuItemIcon}" />
<Setter Property="cal:Action.Target" Value="{Binding}" />
<Setter Property="cal:Message.Attach" 
        Value="[Event Click] = [Action DoCommand()]" />
<Setter Property="Visibility"
        Value="{Binding State, Converter={x:Static converters:Common.VisibilityFromControlState}}" />
<Setter Property="IsEnabled" 
        Value="{Binding State, Converter={x:Static converters:Common.IsEnabledFromControlState}}" />

When a user clicks on the MenuItem, MenuModel.DoCommand() is called as expected. But then the RoutedEvent appears to bubble up, causing DoCommand() to be called on the parent MenuItem. I don't want this behavior. Is there a recommended way to mark the event as handled or some other way to prevent execution of commands on ancestors? I generally try to avoid passing $eventargs, but I might make an exception in this case.