无法从WinRT中的列表框中触发PointerPressed事件 [英] Can't fire PointerPressed event from a Listbox in WinRT

查看:65
本文介绍了无法从WinRT中的列表框中触发PointerPressed事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到某些数据的ListBox,所有数据都设置有ItemTemplate,我想通过按ListBox区域中的任何位置来触发此列表中的PointerPressed事件(因为出于某种目的,我只需要这样做),但是显然这些项目阻止了这种情况,(我正在使用命令)这是我的代码

I have a ListBox bound to some data, all with an ItemTemplate set, I want to fire PointerPressed Event from this list by pressing anywhere in the ListBox area (cause I just need that for some purpose), but apparently the Selection of the items is preventing that, (I'm using commands) here's my code

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

我什至试图从诸如TextBoxes之类的组件之一触发PointerPressed事件,但仍然没有触发.

I even tried to fire the PointerPressed event from one of the components like those TextBoxes but still not firing.

我会很感激,

推荐答案

我现在就放弃.ScrollViewer可以过滤出指针事件,因此您最好找出一种替代设计.

I'd go and just give up at this point. A ScrollViewer filters out pointer events and you will be better off figuring out an alternative design.

这篇关于无法从WinRT中的列表框中触发PointerPressed事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆