2010-11-27 127 views
2

我正在尝试修改Windows Phone 7 TrainingKit(http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=ca23285f-bab8-47fa-b364-11553e076a9a)中包含的UsingBingMaps示例以使用MVVM-Light工具包。我试图使用EventToCommand设置一个命令到Pushpin的MouseLeftButtonUp事件,但是命令没有得到执行。以下是图钉的代码:图钉与EventToCommand

<my:Pushpin Style="{StaticResource PushpinStyle}"           
Location="{Binding Location}" 
Background="{Binding TypeName, Converter={StaticResource PushpinTypeBrushConverter}}"> 
<i:Interaction.Triggers> 
    <i:EventTrigger EventName="MouseLeftButtonUp"> 
    <cmd:EventToCommand Command="{Binding DataContext.PushpinClickCommand, ElementName=HomePage}"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 
<Image Source="{Binding Icon}" /> 
</my:Pushpin> 

我是否缺少任何东西?有人能够使用Pushpin对象的EventToCommand吗?

回答

0

你想用命令做什么?

我可以得到一个命令来使用这个,但我似乎无法从通过参数获取对象的细节。

我已经在Silverlight中使用这一点,我认为这是在WP7直接使用(请纠正我,如果我错了)

 <i:Interaction.Triggers> 
     <i:EventTrigger EventName="MouseLeftButtonUp"> 
       <cmd:EventToCommand Command="{Binding Path=pinSelCommand}" PassEventArgsToCommand="True" ></cmd:EventToCommand> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 

在我的视图模型构造我有

PolySelCommand = new RelayCommand<MouseButtonEventArgs>(PolySelCommandExecute); 

在视图模型类

public RelayCommand<MouseButtonEventArgs> pinSelCommand{ get; set; } 
private voidpinSelCommandExecute(MouseButtonEventArgs e) 
{ 
    // < Your code > 
} 

希望这会有所帮助。如果你弄清楚如何传递物体细节,请回复,因为我有问题on this post