Reputation: 484
I'm trying to trigger an event when the user clicks/taps on a list item to open some more details from the item, but I cannot get to catch the tap on the item, this is my 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>
This is the event I'm trying to trigger(Just trying to catch the tap):
public void OnBandClick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("hello");
}
Upvotes: 0
Views: 1504
Reputation: 1632
Try this code:
void OnBandClick(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if (bandListView.SelectedItem != null)
{
// Do Something
}
}
Upvotes: 1
Reputation: 71
The reported issue “SfListView ItemTapped event does not trigger” occurs due to SfListViewRenderer might not be initialized in your native projects. So, we recommend to refer the following UG documentation link to initialize the SfListView renderer to resolve the issue at the sample level.
Launching SfListView in each platform: https://help.syncfusion.com/xamarin/sflistview/getting-started#launching-the-sflistview-on-each-platform
Upvotes: 1