I'm trying to get a context menu within a ListBox ItemTemplate to call a method on the parent view model, passing in the item that was clicked on as a parameter. I have this working for other buttons in the item template, but for the context menu it seems to be failing.
I have the following xaml (abbreviated for clarity):
<ListBox>
<ListBox.GroupStyle>
<GroupStyle>
...
</GroupStyle>
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ContextMenu>
<ContextMenu Name="cm">
<MenuItem Header="Open"
cal:Message.Attach="Open($dataContext)">
</MenuItem>
</Grid.ContextMenu>
<TextBlock VerticalAlignment="Center" >
.. text..
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a feeling this has to do with the fact that the visual tree is different, so Caliburn is unable to resolve the method reliably. I'm sure this is a common problem, and I've tried a few of the things I've found online, but nothing seems to be working.
Any ideas??
Using the information I found on the Caliburn Micro site I modified your XAML to look like this:
And my view model:
Open was successfully called with the appropriate strings from the list box.