Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms ListView.Behaviors和Prism DelegateCommand<;T>;问题_Xamarin.forms_Prism - Fatal编程技术网

Xamarin.forms ListView.Behaviors和Prism DelegateCommand<;T>;问题

Xamarin.forms ListView.Behaviors和Prism DelegateCommand<;T>;问题,xamarin.forms,prism,Xamarin.forms,Prism,经过数小时的搜索和尝试,我无法使以下内容正常工作 预期行为:轻触列表中的某个项目一次,导航到某个页面。在同一项目上快速点击2-3次(或更多),仍然打开一页而不是更多 我已经成功地做到了这一点,但是当使用一个通用的DelegateCommand时,由于某种原因它就不能工作了。 我使用的是Xamarin.Forms(版本3.1.0.637273)和Prism(版本7.1.0.172-pre) 在我的XAML中,我有一个具有以下行为和绑定的ListView: <ListView Ca

经过数小时的搜索和尝试,我无法使以下内容正常工作

预期行为:轻触列表中的某个项目一次,导航到某个页面。在同一项目上快速点击2-3次(或更多),仍然打开一页而不是更多

我已经成功地做到了这一点,但是当使用一个通用的DelegateCommand时,由于某种原因它就不能工作了。 我使用的是Xamarin.Forms(版本3.1.0.637273)和Prism(版本7.1.0.172-pre)

在我的XAML中,我有一个具有以下行为和绑定的ListView:

<ListView 
     CachingStrategy="RecycleElement"
     ItemsSource="{Binding MyCollection}">
     <ListView.Behaviors>
          <b:EventToCommandBehavior
               Command="{Binding MyCommand}"
               EventName="ItemTapped"
               EventArgsParameterPath="Item" />
     </ListView.Behaviors>
         <ListView.ItemTemplate>
              <DataTemplate>
                   <ViewCell>
                       ...
                   </ViewCell>
              </DataTemplate>
         </ListView.ItemTemplate>
</ListView>
当我不使用DelegateCommand的通用版本时,此代码可以工作


如果有人能告诉我我做错了什么,那就太棒了。谢谢。

你的可观察学院是否由“某个模型”组成?否则就不行了。所以你应该有类似ObservableCollectionCheck@AndresCastro的东西是的,我的ObservableCollection属于“SomeModel”类型,我编辑了我的问题,让事情更清楚。我将发布一个关于这个bug的示例项目,以便人们可以测试它;在使用该方法并解决了我的问题后,我仍然不太高兴。
private ObservableCollection<SomeModel> _myCollection;
public ObservableCollection<SomeModel> MyCollection
{
    get { return _myCollection; }
    set { SetProperty(ref _myCollection, value); }
}

private bool _canNavigate;
public bool CanNavigate
{
     get { return _canNavigate; }
     set { SetProperty(ref _canNavigate, value); }
}


private DelegateCommand<SomeModel> _myCommand;
public DelegateCommand<SomeModel> MyCommand =>
            _someModel ?? (_myCommand = new DelegateCommand<SomeModel>(ExecuteMethod, (parameter) => CanNavigate))
            .ObservesProperty(() => CanNavigate);

private async void ExecuteMethod(SomeModel parameter)
{
     CanNavigate = false;

     NavigationParameters parameters = new NavigationParameters($"?id={parameter.Id}");
     await NavigationService.NavigateAsync("SomeCoolPage", parameters);

     CanNavigate = true;
}
private async void ExecuteCommand()
{
     if(CanNavigate)
     {
          CanNavigate = false;
          ...
          ...
          CanNavigate = true;
     }
}