AymenDaoudi
AymenDaoudi

Reputation: 8299

Can't fire PointerPressed event from a Listbox in WinRT

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>

The code behind :

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

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

I'd be so thankful , thx

Upvotes: 1

Views: 807

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

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.

Upvotes: 1

Related Questions