【问题标题】:How to set a tap event on syncfusion listview item?如何在同步融合列表视图项目上设置点击事件?
【发布时间】:2017-09-01 18:52:26
【问题描述】:

当用户单击/点击列表项以打开该项目的更多详细信息时,我试图触发一个事件,但我无法捕捉到对该项目的点击,这是我的 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");
    }

【问题讨论】:

    标签: c# xaml xamarin data-binding syncfusion


    【解决方案1】:

    试试这个代码:

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

    【讨论】:

      【解决方案2】:

      报告的问题“SfListView ItemTapped 事件未触发”是由于 SfListViewRenderer 可能未在您的本机项目中初始化。因此,我们建议参考以下 UG 文档链接来初始化 SfListView 渲染器,以解决示例级别的问题。

      在各个平台启动SfListView:https://help.syncfusion.com/xamarin/sflistview/getting-started#launching-the-sflistview-on-each-platform

      【讨论】:

      • 由于在文档中遗漏了它,我在这方面花费了太多时间。该列表将显示您的项目,但在未初始化的情况下不会出现不同的功能(例如点击命令)。
      【解决方案3】:

      尝试使用SelectionChanged 事件。 Syncfusion docs 有一整节介绍了控件支持的不同选择模式以及如何使用它们。

      【讨论】:

      • 已经尝试过使用 SelectionChanged 和 SelectionChanging 但无法让它们工作。我一步一步地遵循了来自:help.syncfusion.com/xamarin/sflistview/selection 的文档。
      • 另一件事是没有选择项目。
      • 你设置了 SelectionMode 吗?
      • 是的,我已将其设置为单人
      • 您尝试过他们的示例项目吗?否则我可能会去他们的支持系统寻求更多帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多