扩展的 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...