【问题标题】:Pushpin with EventToCommand带有 EventToCommand 的图钉
【发布时间】:2010-11-27 19:34:10
【问题描述】:

我正在尝试调整 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 事件设置一个命令,但该命令没有被执行。下面是图钉的代码:

<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>

我错过了什么吗?是否有人能够将 EventToCommand 与 Pushpin 对象一起使用?

【问题讨论】:

    标签: windows-phone-7 mvvm-light bing-maps


    【解决方案1】:

    你想用这个命令做什么?

    我可以使用这个命令来触发,但我似乎无法从传递的参数中获取对象详细信息。

    我在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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      相关资源
      最近更新 更多