如何在 syncfusion 列表视图项上设置点击事件?
How to set a tap event on syncfusion listview item?
我试图在列表项上的用户 clicks/taps 打开该项目的更多详细信息时触发一个事件,但我无法捕捉到该项目的点击,这是我的 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>
这是我要触发的事件(只是想抓住点击):
public void OnBandClick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("hello");
}
尝试使用 SelectionChanged
事件。 Syncfusion docs 有一整节介绍控件支持的不同选择模式以及如何使用它们。
报告的问题“SfListView ItemTapped 事件未触发”是由于您的本机项目中可能未初始化 SfListViewRenderer 而导致的。因此,我们建议参考以下UG文档link来初始化SfListView渲染器,以解决示例级别的问题。
在每个平台上启动 SfListView:https://help.syncfusion.com/xamarin/sflistview/getting-started#launching-the-sflistview-on-each-platform
试试这个代码:
void OnBandClick(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if (bandListView.SelectedItem != null)
{
// Do Something
}
}
我试图在列表项上的用户 clicks/taps 打开该项目的更多详细信息时触发一个事件,但我无法捕捉到该项目的点击,这是我的 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>
这是我要触发的事件(只是想抓住点击):
public void OnBandClick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("hello");
}
尝试使用 SelectionChanged
事件。 Syncfusion docs 有一整节介绍控件支持的不同选择模式以及如何使用它们。
报告的问题“SfListView ItemTapped 事件未触发”是由于您的本机项目中可能未初始化 SfListViewRenderer 而导致的。因此,我们建议参考以下UG文档link来初始化SfListView渲染器,以解决示例级别的问题。
在每个平台上启动 SfListView:https://help.syncfusion.com/xamarin/sflistview/getting-started#launching-the-sflistview-on-each-platform
试试这个代码:
void OnBandClick(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if (bandListView.SelectedItem != null)
{
// Do Something
}
}