0

I have an ItemsControl bound to a collection on my ViewModel. This ItemsControl presents several "Messages". I need a ContextMenu that, when clicked, provides an option to Copy that particular message to the clipboard.

The Command should activate on the ViewModel and the CommandParameter I want to pass is the Message itself.

The problem I'm having is getting the actual message that the ContextMenu has been opened OVER.

I've tried mutliple different approaches, but I cannot seem to figure out a way to pass the message as the Command's parameter.

Should I look for a different approach to accomplish this? Is the issue using an ItemsControl with an ItemsPresenter?

<ScrollViewer CanContentScroll="False" 
            VerticalScrollBarVisibility="Auto" 
            HorizontalScrollBarVisibility="Disabled" 
            Grid.RowSpan="1">
            <ItemsControl ItemsSource="{Binding MyActiveConversation.OrderedMessages, UpdateSourceTrigger=PropertyChanged}" 
            IsEnabled="{Binding MyActiveConversation.IsOptOut, Converter={StaticResource BoolToEnabledInverter}}"
            ItemTemplateSelector="{StaticResource tSelector}" 
            VirtualizingPanel.IsVirtualizing="False" 
            SourceUpdated="SourceUpdatedHandler" MinWidth="450">
                <ItemsControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Copy" Template="{DynamicResource MenuItemControlTemplate}" 
                            CommandParameter="{Binding}" Command="{Binding Path=Data.CopyTextMessageCommand, Source={StaticResource ContextProxy}}">
                        </MenuItem>
                    </ContextMenu>
                </ItemsControl.ContextMenu>
                <ItemsControl.Template>
                    <ControlTemplate>
                        <Grid>
                            <ItemsPresenter VirtualizingPanel.IsVirtualizing="False"/>
                        </Grid>
                    </ControlTemplate>
                </ItemsControl.Template>
            </ItemsControl>

JordanTDN
  • 181
  • 1
  • 12

1 Answers1

-1

CommandParameter="{Binding}" works good for me, same for CommandParameter="{Binding .}"

eCorke
  • 858
  • 1
  • 10
  • 24
  • I edited my question to include the XAML. If I use the {Binding} for the CommandParameter, it returns the ViewModel behind the scenes. I'm using a Proxy to retrieve the DataContext. – JordanTDN Feb 17 '16 at 15:12