Windows Phone 8.1 应用点击事件未触发
Windows Phone 8.1 App tapped event not firing
我正在开发 Windows Phone 8.1 应用程序,当我单击 ListView 中的某个项目时,我的点击事件没有触发。
你知道这里出了什么问题吗?
<Page.Resources>
<DataTemplate x:Key="myItem">
<StackPanel>
<Grid>
...
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding ShowDetails}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
...
</Grid>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Pivot Title="Items" Margin="8">
<PivotItem Header="All">
<ListView ItemTemplate="{StaticResource myItem}"
ItemsSource="{Binding Items}"
Background="Transparent">
</PivotItem>
</Pivot>
编辑 1:
问题出在我的 DataTemplate 中的 DataContext。
在我的 DataTemplate 中,上下文是 Item.
有没有办法回到页面 DataContext?
那么,当项目实际位于 ViewModel 中时,项目试图在项目中查找 ShowDetails 命令会发生什么?
在这种情况下,您可以绑定到页面的 DataContext。
Command="{Binding DataContext.ShowDetails, ElementName=PageName}"
我正在开发 Windows Phone 8.1 应用程序,当我单击 ListView 中的某个项目时,我的点击事件没有触发。
你知道这里出了什么问题吗?
<Page.Resources>
<DataTemplate x:Key="myItem">
<StackPanel>
<Grid>
...
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding ShowDetails}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
...
</Grid>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Pivot Title="Items" Margin="8">
<PivotItem Header="All">
<ListView ItemTemplate="{StaticResource myItem}"
ItemsSource="{Binding Items}"
Background="Transparent">
</PivotItem>
</Pivot>
编辑 1:
问题出在我的 DataTemplate 中的 DataContext。 在我的 DataTemplate 中,上下文是 Item.
有没有办法回到页面 DataContext?
那么,当项目实际位于 ViewModel 中时,项目试图在项目中查找 ShowDetails 命令会发生什么?
在这种情况下,您可以绑定到页面的 DataContext。
Command="{Binding DataContext.ShowDetails, ElementName=PageName}"