【发布时间】:2012-12-03 18:11:12
【问题描述】:
就是这样:
Bowls = new ObservableCollection<Bowl>();
SowCommand = new DelegateCommand(param => SowGame(param));
private void SowGame(Object param)
{
Int32 index = Convert.ToInt32(param);
Bowls[index] = ...
}
所以我通过按下按钮 Command="{Binding SowCommand}" 将“参数”传递给 SowGame
param 现在是 Bowl 类型的对象
在 SowGame 中,我想对这个 Bowl 对象做一些事情,并且我知道可以通过使用 Bowls[index of object] 来访问集合中的某个对象。但是如上所述将对象转换为 int 似乎不起作用。
如何获取传递对象的索引?
【问题讨论】:
标签: c# object collections parameters indexing