Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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 MVVMCross iOS表视图单元格绑定_Xamarin_Xamarin.ios_Mvvmcross - Fatal编程技术网

Xamarin MVVMCross iOS表视图单元格绑定

Xamarin MVVMCross iOS表视图单元格绑定,xamarin,xamarin.ios,mvvmcross,Xamarin,Xamarin.ios,Mvvmcross,我对iOS的MVVMCross模型很新。我想处理tableview单元格点击,并获取点击的单元格索引。但我不知道如何访问索引 这是我的视图代码 var menuSource = new MenuTableViewSource(menuTableView, MenuCell.Key, MenuCell.Key); this.menuTableView.Source = menuSource; var set = this.CreateBinding

我对iOS的MVVMCross模型很新。我想处理tableview单元格点击,并获取点击的单元格索引。但我不知道如何访问索引

这是我的视图代码

        var menuSource = new MenuTableViewSource(menuTableView, MenuCell.Key, MenuCell.Key);
        this.menuTableView.Source = menuSource;

        var set = this.CreateBindingSet<BooksView, BooksViewModel>();
        set.Bind(menuSource).To(vm => vm.MenuCellTexts);
        set.Bind(menuSource).For(s => s.SelectionChangedCommand).To(vm => vm.ItemSelectedCommand);
        set.Apply();

您可以通过将所选行对象传递给
命令来尝试查找索引,如下所示:

private MvxCommand<YourClassName> _itemSelectedCommand;
public MvxCommand<YourClassName> ItemSelectedCommand
{
    get
    {
        _itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand(DoSelectedItem);
        return _itemSelectedCommand;
    }
} 

private void DoSelectedItem(YourClassName item)
{
    // How to get the tapped cell index here??

    var index = MenuCellTexts.IndexOf(item);
}
private MvxCommand\u itemSelectedCommand;
公共MvxCommand ItemSelectedCommand
{
得到
{
_itemSelectedCommand=\u itemSelectedCommand??新的MVX命令(DoSelectedItem);
返回_itemSelectedCommand;
}
} 
私有void DoSelectedItem(YourClassName项)
{
//如何在此处获取抽头单元格索引??
var索引=MenuCellText.IndexOf(项目);
}

您可以通过将选定的行对象传递给
命令来尝试查找索引,如下所示:

private MvxCommand<YourClassName> _itemSelectedCommand;
public MvxCommand<YourClassName> ItemSelectedCommand
{
    get
    {
        _itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand(DoSelectedItem);
        return _itemSelectedCommand;
    }
} 

private void DoSelectedItem(YourClassName item)
{
    // How to get the tapped cell index here??

    var index = MenuCellTexts.IndexOf(item);
}
private MvxCommand\u itemSelectedCommand;
公共MvxCommand ItemSelectedCommand
{
得到
{
_itemSelectedCommand=\u itemSelectedCommand??新的MVX命令(DoSelectedItem);
返回_itemSelectedCommand;
}
} 
私有void DoSelectedItem(YourClassName项)
{
//如何在此处获取抽头单元格索引??
var索引=MenuCellText.IndexOf(项目);
}