如何在Xamarin.Forms中对Horizo​​ntalListView进行ItemClick

时间:2017-01-24 10:19:52

标签: xamarin xamarin.forms

https://www.nuget.org/packages/HorizontalListView1.1/

我使用了上面的链接并实现了水平列表。列表即将到来,它正在水平滚动。但是,对于项目点击,我使用了两个属性:

  1. 的SelectedItem
  2. SelectedItemChanged
  3. 但是,我仍然没有得到如何在这里做物品点击事件。

    见下面的代码:

    XAML:

    <ScrollView  Orientation="Horizontal" ><StackLayout Orientation="Horizontal">
     <Controls:HorizontalListView x:Name="packages_listname" ListOrientation="Horizontal"  >
          <Controls:HorizontalListView.ItemTemplate SelectedItemChanged="Item_Changes">
            <DataTemplate>
               <Grid Grid.ColumnSpacing="0">
                   <Grid.RowDefinitions>
                     <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                     <StackLayout Orientation="Horizontal"  Grid.Row="0" BackgroundColor="#282C2B" HeightRequest="60" Spacing="0" Padding="0" Margin="0">
                      <Label Text="{Binding Package_Name}" HorizontalTextAlignment="Start" VerticalTextAlignment="Center" TextColor="White" Margin="0"/>
                       </StackLayout>
                      </Grid>
                   </DataTemplate>
                  </Controls:HorizontalListView.ItemTemplate>
                </Controls:HorizontalListView>
                 </StackLayout>
            </ScrollView>
          </StackLayout>
    

    Code.Cs:

    packages_listname.ItemsSource = packageslist;
    public void Item_Changes(object sender, EventArgs e){
        // var obj = ((HorizontalListView)sender).SelectedItem as PackagesModelClass;
        var obj = packages_listname.SelectedItem as PackagesModelClass;
    
            switch (obj.Package_Name)
            {
                case "Corporate":
                    list_of_corporate.ItemsSource = GetData("Corporate");
    
                    break;
                case "ValueAddGrid":
                    list_of_corporate.ItemsSource = GetData("ValueAddGrid");
                    break;
                case "UtilityGrid":
                    list_of_corporate.ItemsSource = GetData("UtilityGrid");
                    break;
            }
        }
    

0 个答案:

没有答案