MVVM Light - Relaycommand with Pushpins

拟墨画扇 提交于 2019-12-06 04:43:36

I'd move the trigger to the pushpin element.

    <DataTemplate x:Name="ppTemplate">
        <m:Pushpin ToolTipService.ToolTip="{Binding _psName}" Location="{Binding _Location}">
             <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseEnter">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseLeftButtonUp">
                                <cmd:EventToCommand Command="{Binding Path=DataContext.pinSelCommand}" 
                                                    CommandParameter="{Binding WhateverPropertyHasTheText" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
        </m:Pushpin>
    </DataTemplate>

Notice I'm passing as a command parameter whatever property you want to send from the objects in _PinsForDisplay. Also, the binding for the command changed slightly, as the binding is different from inside a datatemplate.

And then you'd have to change your RelayCommand on the viewmodel to RelayCommand.

I didn't test this code, but something very similar is working for me so hopefully it can lead you toward a solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!