我有一个ListBox绑定到一些数据,都有一个ItemTemplate设置,我想通过按ListBox区域中的任何地方从这个列表中激活PointerPressed事件(因为我只需要它用于某种目的),但显然选择这些项目正在阻止,(我正在使用命令)这里是我的代码
<ScrollViewer x:Name="sv"
x:FieldModifier="public"
VerticalScrollBarVisibility="Visible"
VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Disabled"
HorizontalScrollMode="Disabled">
<ListBox x:Name="lb"
ItemsSource="{Binding Path=Tweets}">
<WinRTBehaviors:Interaction.Behaviors>
<Win8LnBehaviors:EventToCommandBehavior Event="PointerPressed"
Command="svPointerPressed"
PassEventArgsToCommand="True" />
</WinRTBehaviors:Interaction.Behaviors>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="65">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="65"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
</Grid.RowDefinitions>
<Image x:Name="Img_ProfilePicture"
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
Stretch="Fill"
Source="{Binding ProfilePictureSource}"
Margin="2">
</Image>
<TextBlock x:Name="Tb_ProfileName"
Grid.Row="0"
Grid.Column="1"
Text="{Binding UserName}"
Margin="5,0,0,0"
FontFamily="Segoe UI Mono"
FontSize="12"
FontWeight="Bold" />
<TextBlock x:Name="Tb_FeedTime"
Grid.Row="0"
Grid.Column="2"
Text="{Binding StatusDateTime}"
Margin="5,0,0,0"
FontFamily="Segoe UI Light"
FontSize="10" />
<TextBlock x:Name="Tb_FeedData"
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Text="{Binding Status}"
Margin="10,0,0,0"
FontFamily="Wasco Sans"
TextWrapping="Wrap">
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
背后的代码:
public RelayCommand<RoutedEventArgs> svPointerPressed
{
get
{
return new RelayCommand<RoutedEventArgs>((routedEventArgs) =>
{
_dispatcher = Window.Current.Dispatcher;
_dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
MessageDialog m = new MessageDialog("Tapped !");
m.ShowAsync();
});
});
}
private set{}
}
我甚至试图从其中一个组件中触发PointerPressed事件,例如那些TextBox但仍未触发。
我会非常感激,谢谢
答案 0 :(得分:1)
我会在这一点上放弃。 ScrollViewer过滤掉指针事件,你最好找出另一种设计。