Xamarin MVVMCross iOS表视图单元格绑定
我对iOS的MVVMCross模型很新。我想处理tableview单元格点击,并获取点击的单元格索引。但我不知道如何访问索引 这是我的视图代码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
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(项目);
}