如何解决扩展的 ListView 的项的命令单击事件不起作用 Xamarin Forms
我有一个可观察的组集合,每个组包含许多参与者。到目前为止,我有一个使用扩展器的可扩展列表视图,一切都显示正常 Screenshot。
但是,当我点击参与者项目时,没有任何反应,并且点击手势不会触发 viewmodel 中的命令方法。我做错了什么?
<ListView ItemsSource="{Binding Groups}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame>
<Expander>
<Expander.Header>
<Grid Padding="10" >
<Label Text="{Binding Name}"/>
</Grid>
</Expander.Header>
<StackLayout BindableLayout.ItemsSource="{Binding Participants}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame CornerRadius="10" Padding="10" Margin="10">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectedCommand}"/>
</Frame.GestureRecognizers>
<StackLayout Padding="5">
<Label Text="{Binding Name}">
</StackLayout>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</Expander>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
viewmodel 类
public class MySessionDetailviewmodel : Baseviewmodel
{
private SessionDto _selectedSession;
public SessionDto SelectedSession
{
get => _selectedSession;
set
{
_selectedSession = value;
OnPropertyChanged();
}
}
private ObservableCollection<GroupDto> _groups;
public ObservableCollection<GroupDto> Groups
{
get => _groups;
set
{
_groups = value;
OnPropertyChanged();
}
}
private ObservableCollection<ParticipantDto> _participants;
public ObservableCollection<ParticipantDto> Participants
{
get => _participants;
set
{
_participants = value;
OnPropertyChanged();
}
}
public ICommand SelectedCommand { get; }
public MySessionDetailviewmodel(INavigationService navigationService,IDialogService dialogService) : base(navigationService,dialogService)
{
SelectedCommand = new Command(OnParticipantTapped);
}
public override async Task InitializeAsync(object session)
{
SelectedSession = (SessionDto)session;
Groups = new ObservableCollection<GroupDto>(SelectedSession.Groups);
Participants = Groups.Select(x => x.Participants).FirstOrDefault().OrderBy(f => f.Number).ToObservableCollection();
}
private void OnParticipantTapped()
{
_navigationService.NavigatetoAsync<Surveyviewmodel>();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。