xamarin - 与 listview 绑定的 observableCollection 的 Xamarin 返回索引
问题描述
如何获取绑定到列表的 observableCollection 的索引?
我希望当用户单击 listview 或 collectionView 上的按钮时,该按钮命令参数返回单击的列表单元格的索引。
命令方法:
private void HT(object id)
{
var x = (id as CategoriesGroup);
int si = ExpandedCategories.IndexOf(x);
Debug.WriteLine("TAAAAAAAAAAAAAAAAPPPPPPPPPPPPEEEEEEEED");
}
XAML 代码
<CollectionView ItemsSource="{Binding ExpandedCategories}" IsGrouped="True">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="1" VerticalItemSpacing="5" HorizontalItemSpacing="5"></GridItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout >
<Label Text="{Binding NameNative}"></Label>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<StackLayout BackgroundColor="AliceBlue">
<Label Text="{Binding Name}" FontSize="Title"></Label>
<Button Image="{Binding StateIcon}"
BackgroundColor="Transparent"
BorderColor="Transparent"
BorderWidth="0"
Command="{Binding BindingContext.ExpandCommand ,Source={x:Reference ServiceListPage}}"
CommandParameter="{Binding}"/>
</StackLayout>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
</CollectionView>
对于录制的第一项,我得到 0 作为正确的索引,其余的我得到 -1
解决方案
推荐阅读
- angular - 如何将数据从一个组件传递到角度 2 中的另一个组件?
- c# - 如果列表 a 等于列表 B 无法正常工作
- f# - F#:对复杂列表进行分组
- r - 如何将按组添加到 t.test?
- x11 - 当我尝试更改双显示方向时 X 服务器崩溃
- ruby - 从类中包含的 mixin 访问类中定义的常量
- php - PHP guzzlehttp 返回与 curl 不同的状态码
- javascript - 如何使用量角器检查页面是否有角度
- python - Keras:ValueError:检查目标时出错:预期dense_2具有形状(10,)但得到形状为(1,)的数组
- excel - 在单元格单击时运行一个宏,在单元格双击时运行另一个宏