xamarin.forms - 绑定到嵌套项
问题描述
我有这个代码:
<StackLayout BindableLayout.ItemsSource="{Binding Classes}">
....
<StackLayout BindableLayout.ItemsSource="{Binding Class1}">
...
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="Class_Tapped" CommandParameter="{Binding .}" />
</StackLayout.GestureRecognizers>
</StackLayout>
</StackLayout>
问题是我得到的是 Classes 而不是 Class1 的绑定。我想要 Tapped CommandParameter 中的 Class1 绑定。这可能吗?
谢谢!
解决方案
放入 的inner StackLayout
,DataTemplate
的outer StackLayout
BindingContextTapGestureRecognizer
必须是Class1
。
<StackLayout BindableLayout.ItemsSource="{Binding Classes}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BindableLayout.ItemsSource="{Binding Class1}">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="Class_Tapped" CommandParameter="{Binding .}" />
</StackLayout.GestureRecognizers>
</StackLayout>
</ViewCell>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
推荐阅读
- c# - 如何使用带有远程主机的 dotnet publish 执行依赖于框架的部署
- python - 如何从文件夹中的多个文件中读取数据并将其提取到 csv/xls 中?
- android - 具有相同高度的两个布局百分比
- python - Matplotlib 插值
- c - 如何在启动时等待 Windows TCP 网络?
- yii2 - 让所有控制器中的每个函数在执行函数之前执行一些代码,而不在 Yii2 中的每个函数中添加代码
- javascript - onclick 事件未在 vue.js 中触发
- javascript - Nested HTTP requests in Firebase cloud function
- php - Laravel 表单复选框数据
- ios - 将 heic 转换为 JPG 并获取文件位置