我想在ListView中单击命令绑定标签,在ListView中,我有一个标签。点击该标签后转到另一页。
我尝试了这个,但没有正常工作。还有其他解决办法吗?
<Label Text="Message" FontSize="12" Grid.Column="3" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
<Label.GestureRecognizers>
<TapGestureRecognizer BindingContext="{Binding Source={x:Reference newsfeedlist}, Path=BindingContext}" Command="{Binding MessageCommand}" CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"/>
</Label.GestureRecognizers>
</Label>
答案 0 :(得分:0)
List视图有自己的bindingContext,所以最好是重新设置页面然后命令,例如
首先给你的页面命名
<ContentPage
....
x:Name="FooPage"
Title="Foo">
然后在你的列表中
<ListView x:Name="EmployeeListData" ItemsSource="{Binding EmployeeList}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5"><Label Text="Click Me">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Path=BindingContext.EmployeeActions, Source={x:Reference FooPage}}" CommandParameter="{Binding .}"></TapGestureRecognizer>
</Label.GestureRecognizers> </Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是秘密来源
Command =&#34; {Binding Path = BindingContext.EmployeeActions,Source = {x:Reference FooPage}}&#34;