【问题标题】:EventTriggerBehavior Tapped not firingEventTriggerBehavior Taped 未触发
【发布时间】:2015-03-30 14:11:03
【问题描述】:

我在我的地图上为图钉使用 MVVM-light 方法。 我已将 Tapped Event 绑定到 ViewModel 中的命令。 然而,事件没有被触发。 所有其他命令和属性都完美绑定。 我也尝试以使用常规事件为例,但它也没有触发。

我的虚拟机中的命令

private RelayCommand<Check> _showDetailCheckCommand;
public RelayCommand<Check> ShowDetailCheckCommand
{
    get
    {
        Debug.WriteLine("Binded");
        return _showDetailCheckCommand ?? (_showDetailCheckCommand = new RelayCommand<Check>((c) =>
        {
            Debug.WriteLine("Action!");
        }));

    }
}

在我的 XAML 中

<Page
    x:Name="pageRoot" 
...


<Maps:MapControl x:Name="Map" IsEnabled="False" Margin="0,8,0,8" MapServiceToken="******" LandmarksVisible="False" PedestrianFeaturesVisible="False" TrafficFlowVisible="True"  ZoomLevel="16">
    <!-- Incidents -->
    <Maps:MapItemsControl ItemsSource="{Binding checks}">
        <Maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <Image Tag="{Binding}" Source="{Binding image_path}" Maps:MapControl.Location="{Binding geodata, Converter={StaticResource RoadsmartCoordinatesToGeoPointConverter}}" Maps:MapControl.NormalizedAnchorPoint=".5,.5" >
                    <interactivity:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="Tapped">
                            <core:InvokeCommandAction Command="{Binding DataContext.ShowDetailCheckCommand, ElementName=pageRoot}" CommandParameter="{Binding}"  />
                        </core:EventTriggerBehavior>
                    </interactivity:Interaction.Behaviors>
                </Image>
            </DataTemplate>
        </Maps:MapItemsControl.ItemTemplate>
    </Maps:MapItemsControl>
</Maps:MapControl>

我的输出日志确实说: '绑定' 但是当我点击地图上的图像时,'Action' 没有被执行。

【问题讨论】:

  • 它会从那个事件中触发吗?你确定它是你想要的“点击”而不是像 Clicked 或 MouseLeftButtonDown 等?这是RT吗?我的意思是乍一看它看起来是合法的。
  • Windows 通用。事件名称为 Tapped,Image 控件上没有 Clicked Event。在后面的代码中处理事件时也不会触发该事件
  • 你需要DataContext.ShowDetailCheckCommand中的DataContext吗?取决于页面的 DataContext 是如何设置的
  • 是的,我确实需要它。我的 Datacontext 不是我的代码,而是一个 ViewModel。未在 XAML 中设置 Datacontext 时出现绑定错误。

标签: c# xaml mvvm mvvm-light behavior


【解决方案1】:

我太傻了。 我将 Map 属性 isEnabled 设置为 false

这很令人困惑,因为所有 Map 手势都有效,但没有一个绑定在其之上的 XAML 控件。

愚蠢的错误,但它可能会帮助人们。

【讨论】:

    猜你喜欢
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多