2017-09-01 109 views
0

我想一个列表项,当用户点击/轻敲从项目开一些更多的细节,触发一个事件,但我不能让捉对项目的水龙头,这是我的ListView:如何在syncfusion listview项目上设置轻击事件?

  <syncfusion:SfListView x:Name="bandListView" 
       ItemsSource="{Binding Source={local2:BandInfoRepository}, Path=BandInfo, Mode=TwoWay}" 
       ItemSize="100" 
       ItemTapped="OnBandClick" 
       AbsoluteLayout.LayoutBounds="1,1,1,1" 
       AbsoluteLayout.LayoutFlags="All" > 
       <syncfusion:SfListView.ItemTemplate> 
        <DataTemplate> 
         <Grid RowSpacing="0" Padding="0,12,8,0" ColumnSpacing="0" Margin="5"> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto" /> 
           <RowDefinition Height="1" /> 
          </Grid.RowDefinitions> 
          <Grid RowSpacing="5" Padding="8,10,8,10" BackgroundColor="#dbe8ff"> 
           <Grid.RowDefinitions> 
            <RowDefinition Height="0.9*" /> 
           </Grid.RowDefinitions> 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="Auto" /> 
            <ColumnDefinition Width="Auto" /> 
           </Grid.ColumnDefinitions> 
           <Image Source="{Binding Path=BandImage}" 
            Grid.Column="0" 
            Grid.Row="0" 
            HeightRequest="80" 
            WidthRequest="70" 
            HorizontalOptions="Start" 
            VerticalOptions="Start" 
           /> 
           <StackLayout Orientation="Vertical" 
            Padding="5,-5,0,0" 
            VerticalOptions="Start" 
            Grid.Row="0" 
            Grid.Column="1"> 
            <Label Text="{Binding Path=BandName}" 
             FontAttributes="Bold" 
             FontSize="16" 
             TextColor="#000000" /> 
            <Label Text="{Binding Path=BandDescription}" 
             Opacity="0.54" 
             TextColor="#000000" 
             FontSize="13" /> 
           </StackLayout> 
          </Grid> 
          <BoxView Grid.Row="1" 
           HeightRequest="1" 
           Opacity="0.75" 
           BackgroundColor="#CECECE" /> 
         </Grid> 
        </DataTemplate> 
       </syncfusion:SfListView.ItemTemplate> 
      </syncfusion:SfListView> 

这是我想要触发事件(只是试图赶上TAP):

public void OnBandClick(object sender, EventArgs e) 
    { 
     System.Diagnostics.Debug.WriteLine("hello"); 
    } 

回答

1

试试这个代码:

void OnBandClick(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e) 
{ 
    if (bandListView.SelectedItem != null) 
    { 
     // Do Something 
    } 
} 
0

尝试使用SelectionChanged事件。 Syncfusion docs有关于控制器支持的不同选择模式以及如何使用它们的完整章节。

+0

用的SelectionChanged和SelectionChanging已经尝试过,但不能让他们的工作。我按照https://help.syncfusion.com/xamarin/sflistview/selection中的文档逐步进行了操作。 –

+0

另一件事是项目没有被选中。 –

+0

你有SelectionMode设置吗? – Jason

相关问题