我有 listboxitem 的模板。模板包含复选框。总是,当我检查它时,会触发 Tap 事件。但是只有当我选择项目时,Tap 才必须触发,而不是当我选中复选框时。我尝试使用 SelctionChanged 事件,这工作正常。但由于 mvvm 模式,我想使用交互。这是我的 xaml 代码。
<ListBox x:Name="lstboxDevicePositions" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding DevicePositions}" SelectedIndex="{Binding SelectedIndexDevicePosition, Mode=TwoWay}" SelectedItem="{Binding SelectedDevicePosition, Mode=TwoWay}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Border Background="#709DFF" Margin="1,0,1,2" CornerRadius="2" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<CheckBox x:Name="cbxSelected" Grid.Column="0" Grid.RowSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsChecked="{Binding IsSelected, Mode=TwoWay}" />
<TextBlock x:Name="txtblockBindedAddress" Grid.Column="1" Grid.Row="0" TextWrapping="Wrap" Text="{Binding Address}" />
<TextBlock x:Name="txtblockBindedDate" Grid.Column="1" Grid.Row="1" Text="{Binding Date}" />
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cmd:EventToCommand Command="{Binding ShowDevicePositionCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
编辑
问题是,复选框和列表框有 Tap 事件。所以当我点击复选框事件时被触发。我只想在点击 listboxitem 时触发 Tap 事件。