ListView SelectedItem绑定不工作
我正在Android中为我的Xamarin表单项目使用一个定制的ListView SelectedItem绑定不工作,listview,xamarin.android,xamarin.forms,Listview,Xamarin.android,Xamarin.forms,我正在Android中为我的Xamarin表单项目使用一个定制的LabelRenderer。 在这个LabelRenderer中,我使用Control.SetTextIsSelectable(true)以便人们可以从给定的标签复制/粘贴文本。(此方法可在Android internal上使用TextView) 这一切都是可行的,但是通过在列表视图.ItemTemplate中使用它(只是带有一些标签的堆栈布局),列表视图.SelectedItem将不再有效。 正确地说,如果您设法在ItemTemp
LabelRenderer
。
在这个LabelRenderer
中,我使用Control.SetTextIsSelectable(true)
以便人们可以从给定的标签复制/粘贴文本。(此方法可在Android internal上使用TextView
)
这一切都是可行的,但是通过在列表视图.ItemTemplate
中使用它(只是带有一些标签的堆栈布局),列表视图.SelectedItem
将不再有效。
正确地说,如果您设法在ItemTemplate内的标签边界之外点击,它将起作用。因此,SelectedItem绑定的触摸事件被标签吃掉,因为它需要寻找点击选择以启用复制/粘贴功能:/
换句话说,当标签以通用方式在
列表视图中使用时,我们如何禁用标签的触摸行为?尝试将标签的属性InputTransparent
设置为true。这样,标签上的触摸事件将被忽略,并被其父项捕获
更新
如果InputTransparent
不适合您,请从
页面中的示例:
yourList.SetBinding<IYourPageViewModel>(ListViewItemTappedAttached.CommandProperty, x => x.YourCommand);
yourList.SetBinding(ListViewItemTappedAttached.CommandProperty,x=>x.YourCommand);
在您的视图模型中:
YourCommand = new Command<IYourCellViewModel>(item => yourMethod(item));
YourCommand=newcommand(item=>yourMethod(item));
尝试将标签的属性InputTransparent
设置为true。这样,标签上的触摸事件将被忽略,并被其父项捕获
更新
如果InputTransparent
不适合您,请从
页面中的示例:
yourList.SetBinding<IYourPageViewModel>(ListViewItemTappedAttached.CommandProperty, x => x.YourCommand);
yourList.SetBinding(ListViewItemTappedAttached.CommandProperty,x=>x.YourCommand);
在您的视图模型中:
YourCommand = new Command<IYourCellViewModel>(item => yourMethod(item));
YourCommand=newcommand(item=>yourMethod(item));
对不起,我应该提到我已经尝试过了,但仍然事件不会进入SelectedItem对不起,我应该提到我已经尝试过了,仍然事件不会进入SelectedItem